473,231 Members | 2,035 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,231 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 1961
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.