Question: Load bmp and save as jpg

O

Olaf Baeyens

I want to convert one bitmap file to another one.
For example load as bmp and save as jpg.
The loading part is simple I do this:

Stream BitmapStream =
File.Open(sSrcFile,FileMode.Open,FileAccess.Read,FileShare.None);
Bitmap imgPhoto=new Bitmap(BitmapStream);
iPixelsX=imgPhoto.Width;
iPixelsY=imgPhoto.Height;
BitmapStream.Close();

The saving will be something like this; but I fail to see how I can hook up
imgPhoto from the load to this stream.:

Stream DestBitmapStream =
File.Open(DstFile,FileMode.CreateNew,FileAccess.Write,FileShare.None);
// how do I connect imgPhoto?
DestBitmapStream.Close();

Also I wonder if the Pixelfomat is different, lest say I load 8 bit indexed
color palette bitmap and want to save as 24 bit RGB jpeg, could this be done
automatic?
Something tells me that I need to copy the bytes manually??? I hope not.

Many thanks.

Olaf
 
O

Ollie Riches

how about:

....
Size size = new Size(iPixelsX=imgPhoto.Width, iPixelsY=imgPhoto.Height);

Image sourceImage = Image.FromFile("c:\\test.bmp");
Bitmap bitmap = new Bitmap(sourceImage, size);
bitmap.Save("C:\\test.jpeg", ImageFormat.Jpeg);

bitmap.Dispose();
sourceImage.Dispose();

Check out Bob Powell's website for more on GDI+ etc...

http://www.bobpowell.net/gdiplus_faq.htm

HTH

Ollie Riches
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top