469,330 Members | 1,373 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,330 developers. It's quick & easy.

Help when saving images to bitmap files

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+.
The code I have tried is as follows

METHOD 1:

Dim flfile As New System.IO.FileStream(strFileName,
IO.FileMode.OpenOrCreate, IO.FileAccess.Write)
picImage.Image.Save(flfile, System.Drawing.Imaging.ImageFormat.Bmp)
flfile.Close()

METHOD 2:

picImage.Image.Save(strFileName, System.Drawing.Imaging.ImageFormat.Bmp)
In both cases strFileName is the path and name of the file to write to and
picImage is a picturebox currently displaying the image in my application.

Does anyone know what is causing the error and how I can get around it?
--
M Keeton
Nov 23 '05 #1
1 1746
Hi, MKeeton,
I tried out both of your code snippets below (I'm using VS2005), and they both worked fine for me. I added a GIF called "MyImage" to my resources, assigned the value of My.Resources.MyImage to picImage, and then saved it as a BMP in the same way as you tried below. I used c:\foo.bmp as the place to save it to.

This makes me wonder:

(1) What the value is of picImage. Stupid question, and I apologize for asking it, but are you sure it's been assigned the right thing, and that the image hasn't been disposed or anything like that?
(2) Any chance that the place you're saving it to has odd permissions?

Unfortunately, nothing else obvious comes to mind. :-( Let us know...

--Matt Gertz--*
VB Compiler Dev Lead

-----Original Message-----
From: MKeeton
Posted At: Monday, November 14, 2005 6:29 AM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Help when saving images to bitmap files
Subject: Help when saving images to bitmap files
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+.
The code I have tried is as follows

METHOD 1:

Dim flfile As New System.IO.FileStream(strFileName,
IO.FileMode.OpenOrCreate, IO.FileAccess.Write)
picImage.Image.Save(flfile, System.Drawing.Imaging.ImageFormat.Bmp)
flfile.Close()

METHOD 2:

picImage.Image.Save(strFileName, System.Drawing.Imaging.ImageFormat.Bmp)
In both cases strFileName is the path and name of the file to write to and
picImage is a picturebox currently displaying the image in my application.

Does anyone know what is causing the error and how I can get around it?
--
M Keeton
Nov 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Vinay | last post: by
4 posts views Thread by CodeRazor | last post: by
2 posts views Thread by Thaynann | last post: by
5 posts views Thread by TheGanjaMan | last post: by
reply views Thread by Marcus Kwok | last post: by
reply views Thread by Purva khokhar | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.