Saving Image as ImageFormat.Bmp doesn't work

P

Peder Y

My code is something like this:

---------------

Image img = Image.FromFile("somefile.bmp");

FileStream fStream = new FileStream("someBinaryFile.dat");
BinaryWriter bw = new BinaryWriter(fStream);

img.Save(bw.BaseStream, ImageFormat.Bmp);

bw.Close();
fStream.Close();

---------------

When I display the bw.BaseStream.Position before and after the save
operation, it appears to go backwards! Saving Gif's and jpg's works.
Anyone got an idea? Thanks!

- Peder -
 
G

Guest

Hi,

I've never any problem with BMP's saving.
Did you try to remove "BinaryWriter" and save it
only by:

FileStream fStream=FileStream("filename", FileMode.Create,
FileAccess.Write);
try {
img.Save(fStream, ImageFormat.Bmp);
}
finally {
fStream.Close();
}

Did you get any exception in your case?

Regards

Marcin
 
P

Peder Y

No, I haven't tried this approach, but am sure there must be something
else going wrong. Why else would jpg and gif go ok? My challenge is,
however, to take a bunch of different image files, and construct my
own native fileformat where all those original files are embedded
inside my new file. i have solved this by using a binarystream, saving
the number of pictures, and then for each picture, save type ("bmp",
"gif" etc), size in bytes, and the image.

- Peder -
 

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