473,417 Members | 1,540 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,417 software developers and data experts.

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 1971
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Vinay | last post by:
Hi All: I have a small application that stores images either in the database or as files (depending on the user preference). I'm in the process of providing a web interface to this application....
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...
2
by: Thaynann | last post by:
i have an appliation that, at this stage, uses the HttpWebRequest and WebResponse objects to get a stream (as a string) on a page on a web site, i wanted to know, after lookin through the string...
13
by: DavidS | last post by:
I have HTML web page with <asp:Image id=img_L runat=server ImageAlign=Top Visible=True Width=y Height=x></asp:Image>. For some images, less than 128K I can view image. Other image files > 128K,...
7
by: chad | last post by:
is it just me or does anybody else find the Image.RotateFlip method kind of slow? (I'm comparing to commercial softwares). Same for resizing. I'm using sourceImage =...
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...
7
by: Niyazi | last post by:
Hi, I am developing small insurance application using VB.NET and SQL server 2000. My tables in SQL server are: tbl_Customer (stores the custmer information) tbl_CustImage ...
0
by: Marcus Kwok | last post by:
I have written a class (Windows Form) in Managed C++ that accepts an array of image filenames and will display them sequentially. All images will be the same size. I got it to work, but I know...
16
by: AAaron123 | last post by:
I have a timer. At each tick, say 0.1 second, I write a file. If it takes more than 0.1 second to write the file the app will not work correctly. How can I tell in the tick event if the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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...
0
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...

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.