By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,949 Members | 1,511 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,949 IT Pros & Developers. It's quick & easy.

Help when saving images to bitmap files

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.