472,145 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

Saving Image as ImageFormat.Bmp doesn't work

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 -
Nov 16 '05 #1
2 3672
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
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 -

Nov 16 '05 #2
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 -

Marcin Grz?bski <mg*******@taxussi.no.com.spam.pl> wrote in message news:<ci**********@atlantis.news.tpi.pl>...
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
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 -

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Michael Kennedy [UB] | last post: by
4 posts views Thread by CodeRazor | last post: by
1 post views Thread by toma | last post: by
2 posts views Thread by asad | last post: by
1 post views Thread by M Keeton | last post: by
3 posts views Thread by Jason Barnett | last post: by
5 posts views Thread by TheGanjaMan | last post: by
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.