473,511 Members | 16,846 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A generic error occurred in GDI+.

13 New Member
I am getting this error. I know it must have something to do with the Memory Streams I am creating, and I am disposing of them, so I am not sure what the problem is. My application has two steps...first to acquire an image from a twain device. I am placing the image into a memory stream and then setting that image from the memory stream to a picture box...
Expand|Select|Wrap|Line Numbers
  1. public static System.Drawing.Image DIB_ToImage(System.IntPtr hdib)
  2.         {
  3.             System.Drawing.Image convertedImage = null;
  4.             if( hdib != System.IntPtr.Zero ) {
  5.                 byte[] imageDataAsByte = new byte[ DIB_Size( hdib ) + 100 ];
  6.                 GCHandle byteArrayHandle = GCHandle.Alloc( imageDataAsByte, GCHandleType.Pinned );
  7.                 DIB_WriteToBuffer(
  8.                     hdib, TWFF_BMP, byteArrayHandle.AddrOfPinnedObject(), imageDataAsByte.Length );
  9.                 byteArrayHandle.Free();
  10.                 System.IO.MemoryStream memoryStream = new System.IO.MemoryStream( imageDataAsByte, false );
  11.                 System.Drawing.Image temporaryBitmap = System.Drawing.Bitmap.FromStream( ((System.IO.Stream)memoryStream) );
  12.                 convertedImage = (System.Drawing.Image)temporaryBitmap.Clone();
  13.                 temporaryBitmap.Dispose();
  14.                 memoryStream.Dispose();
  15.             }
  16.             return convertedImage;
  17.         }
  18.  
The above code is from a declaration file for a TWAIN program I am using. I am then calling the above...
Expand|Select|Wrap|Line Numbers
  1.                 if (hdib != IntPtr.Zero)
  2.                 {
  3.                     pbImage.Image = EZTwain.DIB_ToImage(hdib);
  4.                     btnSave.Enabled = true;
  5.                     EZTwain.DIB_Free(hdib);
  6.                 }
  7.  
This all works fine. But then when I click the save button is when I get the GDI error...
Expand|Select|Wrap|Line Numbers
  1.                 MemoryStream ms = new MemoryStream();
  2.                 pbImage.Image.Save(ms, pbImage.Image.RawFormat);
  3.                 byte[] img = ms.GetBuffer();
  4.                 ms.Dispose();
The error happens on the line...
Expand|Select|Wrap|Line Numbers
  1. pbImage.Image.Save(ms, pbImage.Image.RawFormat);
Oct 12 '09 #1
0 2262

Sign in to post your reply or Sign up for a free account.

Similar topics

4
48183
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+....
2
22280
by: Alphonse Giambrone | last post by:
I am currently reading 'Programming The Web with Visual Basic .NET' and have so far found it to be excellent. Downloaded all the code from Apress and working in chapter 4, I get the error shown...
2
4870
by: Tim::.. | last post by:
Hi can someone please tell me why I keep getting the following error and how I might fix it ...::ERROR::. Exception Details: System.Runtime.InteropServices.ExternalException: A generic error...
0
1181
by: Eduard | last post by:
Hey folks, I'm creating an image gallery Custom Web Control. The idea is, that i point to a folder using the web.config, which makes that folder the 'Image Gallery Folder' Each subfolder created,...
15
5302
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
0
1382
by: manini | last post by:
Hello Everyone I m getting the generic GDI + error,Please help me to resolve this error ************** Exception Text ************** System.Runtime.InteropServices.ExternalException: A generic...
0
4233
by: =?Utf-8?B?Sm9hY2hpbQ==?= | last post by:
I have a bitmap which I have retreived through the WebBrowser DrawToBitmap method into a Bitmap. When I try to save the bitmap I get "ExternalException occurred A generic error occurred in...
7
10366
by: j4richard | last post by:
Help please, I am getting this "Unhandled Exception has occurred in your application" " A Generic error occurred in GDI+" See the end of this message for details on...
1
3977
by: Jeff | last post by:
hi asp.net 2.0 I'm experimenting with GDI+ in asp.net and get an "A generic error occurred in GDI+." exception. Below is my code, I've marked a line with "<<<<-- here". It's here the...
3
3303
by: uday1302 | last post by:
Hi Dear, Here I am trying to upload a photo. protected void LoadImage() { string UserName = Session.ToString(); byte Data = Profile.GetImageData(UserName);...
0
7242
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
7423
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...
1
7081
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7510
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
5668
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5066
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...
0
3225
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1576
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 ...
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.