473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 3748
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Michael Kennedy [UB] | last post by:
Hi Everyone, I have this multithreaded C# windows forms application which does a lot of image processing. Occasionally, I get the following error: A generic error occurred in GDI+....
3
by: cdj | last post by:
Hi all, I've got a picturebox on a form, and a save button. When I go to save, the app craps out with the following error: ================== An unhandled exception of type...
4
by: CodeRazor | last post by:
I'm unfamiliar with image manipulation using c#. How can i resize a jpg that currently exists in a file and save it resized as a new file. The examples i've found have been a bit misleading for...
1
by: toma | last post by:
Hi! I found out how to manipulate (read,resize, etc..) images using System.Drawin namespace from this site: http://authors.aspalliance.com/chrisg/default.asp?category=9 But i don't know how to...
2
by: asad | last post by:
Hello friends, how ru all, i have some problem about saving created thumbnail, following is the code i use for creating thumbnail but thumbnail was not saved it is on memory which method is used to...
2
by: Brad | last post by:
I have code which takes an image, uploaded from a web page, and saves it to a database. Now I want to always resize an uploaded image before it is saved to the database. My code to resize is...
1
by: M Keeton | last post by:
I currently have a picture which is stored in a "System.Drawing.Image" variable and I want to save it as a bitmap file. I have tried 2 different approaches and both give me the following error: ...
3
by: Jason Barnett | last post by:
When trying to save an image as an icon, I've used the following line of code (img is an System.Drawing.Image)... img.Save("C:\output.ico", ImageFormat.Icon) The files saves without an error,...
5
by: TheGanjaMan | last post by:
Hi everyone, I'm trying to write up a simple image stamper application that stamps the Exif date information from the jpegs that I've taken from my digital camera and saves the new file with the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.