473,729 Members | 2,108 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Saving Image as ImageFormat.Bmp doesn't work

My code is something like this:

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

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

FileStream fStream = new FileStream("som eBinaryFile.dat ");
BinaryWriter bw = new BinaryWriter(fS tream);

img.Save(bw.Bas eStream, ImageFormat.Bmp );

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

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

When I display the bw.BaseStream.P osition 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 3762
Hi,

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

FileStream fStream=FileStr eam("filename", FileMode.Create ,
FileAccess.Writ e);
try {
img.Save(fStrea m, 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("som eBinaryFile.dat ");
BinaryWriter bw = new BinaryWriter(fS tream);

img.Save(bw.Bas eStream, ImageFormat.Bmp );

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

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

When I display the bw.BaseStream.P osition 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*******@taxu ssi.no.com.spam .pl> wrote in message news:<ci******* ***@atlantis.ne ws.tpi.pl>...
Hi,

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

FileStream fStream=FileStr eam("filename", FileMode.Create ,
FileAccess.Writ e);
try {
img.Save(fStrea m, 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("som eBinaryFile.dat ");
BinaryWriter bw = new BinaryWriter(fS tream);

img.Save(bw.Bas eStream, ImageFormat.Bmp );

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

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

When I display the bw.BaseStream.P osition 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
48229
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+. System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+. at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
3
3624
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 'System.Runtime.InteropServices.ExternalException' occurred in system.drawing.dll
4
4247
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 my particular requirements.
1
2579
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 save resize image on hard disc. So i hope someon could help me. The biggest problem is that i run win98 system so no .Net framework testing is possible. If someone could give me a hint on how to change this asp code to actualy
2
1925
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 store created thumbnail in to hard disk <%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %> <%@ Import Namespace="System.Drawing.Imaging"%>
2
3996
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 below and of course it's not working properly because my web page which displays the resulting image from the database is not showing the image. I **think** the problem is in my converting the bitmap back to a byte array. If I change my code back...
1
1995
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: An unhandled exception of type 'System.Runtime.InteropServices.ExternalException' occurred in system.drawing.dll Additional information: A generic error occurred in GDI+.
3
6086
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, and it can be opened by Windows Picture and Fax Viewer, but I cannot assign the image as a form icon. Does anyone know what I can do to get this to work?
5
4732
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 date stamped on the lower right part of the picture. (I'm not an advanced programmer so my code may not be 100% efficient - sorry, I'm still learning) Everything works fine until the saving part. I've been able to read the file into a...
0
8931
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9428
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9293
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9162
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4799
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3246
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2701
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2171
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.