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+.
System.Runtime. InteropServices .ExternalExcept ion: A generic error occurred
in GDI+.
at System.Drawing. Image.Save(Stri ng filename, ImageCodecInfo encoder,
EncoderParamete rs encoderParams)
at System.Drawing. Image.Save(Stri ng filename, ImageFormat format)
It's very strange. Most of the time it works without a problem. But
sometimes I get this error. It can happen with the same source image which
just worked previously and will work next time.
Does anyone know what's causing this? "A generic error" is quiet unhelpful
tracking this down.
Thanks for any help.
Regards,
Michael
Michael Kennedy http://www.unittesting.com 4 48192
Hi Michael,
The save method of Image class is not thread safe.
Here is what MSDN said,
Any public static (Shared in Visual Basic) members of this type are safe
for multithreaded operations. Any instance members are not guaranteed to be
thread safe.
For more information, you may refer to the link below. http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemdraw ingimageclasssa vetopic.asp
So I think you may try to invoke the Save method in one thread, which will
avoid the problem.
Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
-------------------- From: "Michael Kennedy [UB]" <mk******@REMOV ETHIS.unitedbin ary.com> Subject: Generic GDI+ Error when saving bitmaps Date: Wed, 10 Sep 2003 11:04:08 -0700 Lines: 28 Organization : United Binary, LLC. X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Message-ID: <uO************ **@tk2msftngp13 .phx.gbl> Newsgroups: microsoft.publi c.dotnet.genera l NNTP-Posting-Host: 130.191.240.187 Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!tk2 msftngp13.phx.g bl Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:108001 X-Tomcat-NG: microsoft.publi c.dotnet.genera l
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+. System.Runtime .InteropService s.ExternalExcep tion: A generic error occurred in GDI+. at System.Drawing. Image.Save(Stri ng filename, ImageCodecInfo encoder, EncoderParamet ers encoderParams) at System.Drawing. Image.Save(Stri ng filename, ImageFormat format)
It's very strange. Most of the time it works without a problem. But sometimes I get this error. It can happen with the same source image which just worked previously and will work next time.
Does anyone know what's causing this? "A generic error" is quiet unhelpful tracking this down.
Thanks for any help.
Regards, Michael
Michael Kennedy http://www.unittesting.com
Hi Peter,
Thanks for the info. However, I did *not* assume that the Save method was
thread-safe. I only call Save once, from one thread for any given instance
of the Bitmap class. Perhaps some more info would be useful here. This is
the basic flow of events involving the Bitmap.
I have a loop running in a worker thread which rebuilds scenes and then adds
them to a control and list of controls which render copies of the images in
the main GUI thread of the application. Here is a cut-down version of the
thread which does the image generating and the other simply sets the values
of PictureBox's Image property and lets them repaint themselves (indirectly
through the ThumbnailContro l class):
public void ProcessScenes()
{
foreach (Scene s in scenes)
{
renderer.Curren tScene = s;
renderer.Rebuil dSceneImage();
// ... (non-image related stuff)
string file = FILENAME;
try
{
Image sceneImage = new Bitmap(renderer .SceneImage);
sceneImage.Save (file, ImageFormat.Png ); // <-- HERE IS THE GENERIC
ERROR
sceneImage.Disp ose();
}
catch (Exception ex)
{
Trace.WriteLine (ex);
// ... (handle error)
}
Bitmap oldImage = thumbnailContro l.SourceImage;
thumbnailContro lCurrent.Source Image = new Bitmap(renderer .SceneImage);
if (oldImage != null)
{
oldImage.Dispos e();
}
thumbnailPageCo ntrol1.AddThumb nail(new ThumbnailPageCo ntrol(new
Bitmap(renderer .SceneImage)));
}
}
What could be going on here? Any ideas?
Thanks,
Michael
"Peter Huang [MSFT]" <v-******@online.m icrosoft.com> wrote in message
news:Bb******** ******@cpmsftng xa06.phx.gbl... Hi Michael,
The save method of Image class is not thread safe.
Here is what MSDN said, Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to
be thread safe.
For more information, you may refer to the link below. http://msdn.microsoft.com/library/de...us/cpref/html/ frlrfsystemdraw ingimageclasssa vetopic.asp
So I think you may try to invoke the Save method in one thread, which will avoid the problem.
Regards, Peter Huang Microsoft Online Partner Support Get Secure! www.microsoft.com/security This posting is provided "as is" with no warranties and confers no rights.
--------------------From: "Michael Kennedy [UB]" <mk******@REMOV ETHIS.unitedbin ary.com> Subject: Generic GDI+ Error when saving bitmaps Date: Wed, 10 Sep 2003 11:04:08 -0700 Lines: 28 Organization : United Binary, LLC. X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Message-ID: <uO************ **@tk2msftngp13 .phx.gbl> Newsgroups: microsoft.publi c.dotnet.genera l NNTP-Posting-Host: 130.191.240.187 Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!tk2 msftngp13.phx.g bl Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:108001 X-Tomcat-NG: microsoft.publi c.dotnet.genera l
Hi Everyone,
I have this multithreaded C# windows forms application which does a lot
ofimage processing. Occasionally, I get the following error:
A generic error occurred in GDI+. System.Runtime .InteropService s.ExternalExcep tion: A generic error
occurredin GDI+. at System.Drawing. Image.Save(Stri ng filename, ImageCodecInfo encoder, EncoderParamet ers encoderParams) at System.Drawing. Image.Save(Stri ng filename, ImageFormat format)
It's very strange. Most of the time it works without a problem. But sometimes I get this error. It can happen with the same source image
whichjust worked previously and will work next time.
Does anyone know what's causing this? "A generic error" is quiet
unhelpfultracking this down.
Thanks for any help.
Regards, Michael
Michael Kennedy http://www.unittesting.com
Hi Michael,
To isolated the problem,
1.you may try to replace your code as follows. Image sceneImage = new Bitmap(renderer .SceneImage); sceneImage.Save (file, ImageFormat.Png ); // <-- HERE IS THE GENERIC ERROR
with
Image sceneImage = new Bitmap(@"c:\tes t.bmp");
sceneImage.Save (file, ImageFormat.Png ); // <-- HERE IS THE GENERIC
2. You may try to Create a new project and modify your code to be single
threaded to see if the problem persists.
[You may only need to copy the necessary code to reproduce the problem in a
single threaded environment.
Please perform the test and let me know the result.
Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------From: "Michael Kennedy [UB]" <mk******@REMOV ETHIS.unitedbin ary.com> References: <uO************ **@tk2msftngp13 .phx.gbl>
<Bb************ **@cpmsftngxa06 .phx.gbl>Subject: Re: Generic GDI+ Error when saving bitmaps Date: Mon, 15 Sep 2003 13:21:31 -0700 Lines: 133 Organization : United Binary, LLC. X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Message-ID: <ef************ *@TK2MSFTNGP11. phx.gbl> Newsgroups: microsoft.publi c.dotnet.genera l NNTP-Posting-Host: 130.191.240.187 Path:
cpmsftngxa07.ph x.gbl!cpmsftngx a10.phx.gbl!TK2 MSFTNGXA05.phx. gbl!TK2MSFTNGP0 8
..phx.gbl!TK2MS FTNGP11.phx.gblXref: cpmsftngxa07.ph x.gbl microsoft.publi c.dotnet.genera l:108293 X-Tomcat-NG: microsoft.publi c.dotnet.genera l
Hi Peter,
Thanks for the info. However, I did *not* assume that the Save method was thread-safe. I only call Save once, from one thread for any given instance of the Bitmap class. Perhaps some more info would be useful here. This is the basic flow of events involving the Bitmap.
I have a loop running in a worker thread which rebuilds scenes and then
addsthem to a control and list of controls which render copies of the images in the main GUI thread of the application. Here is a cut-down version of the thread which does the image generating and the other simply sets the values of PictureBox's Image property and lets them repaint themselves (indirectly through the ThumbnailContro l class):
public void ProcessScenes() { foreach (Scene s in scenes) { renderer.Curren tScene = s; renderer.Rebuil dSceneImage();
// ... (non-image related stuff)
string file = FILENAME; try { Image sceneImage = new Bitmap(renderer .SceneImage); sceneImage.Save (file, ImageFormat.Png ); // <-- HERE IS THE GENERIC ERROR sceneImage.Disp ose(); } catch (Exception ex) { Trace.WriteLine (ex); // ... (handle error) }
Bitmap oldImage = thumbnailContro l.SourceImage; thumbnailContro lCurrent.Source Image = new
Bitmap(renderer .SceneImage); if (oldImage != null) { oldImage.Dispos e(); } thumbnailPageCo ntrol1.AddThumb nail(new ThumbnailPageCo ntrol(new Bitmap(rendere r.SceneImage))) ; } }
What could be going on here? Any ideas?
Thanks, Michael
"Peter Huang [MSFT]" <v-******@online.m icrosoft.com> wrote in message news:Bb******* *******@cpmsftn gxa06.phx.gbl.. . Hi Michael,
The save method of Image class is not thread safe.
Here is what MSDN said, Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe.
For more information, you may refer to the link below. http://msdn.microsoft.com/library/de...-us/cpref/html
/ frlrfsystemdraw ingimageclasssa vetopic.asp
So I think you may try to invoke the Save method in one thread, which
will avoid the problem.
Regards, Peter Huang Microsoft Online Partner Support Get Secure! www.microsoft.com/security This posting is provided "as is" with no warranties and confers no
rights. -------------------- >From: "Michael Kennedy [UB]" <mk******@REMOV ETHIS.unitedbin ary.com> >Subject: Generic GDI+ Error when saving bitmaps >Date: Wed, 10 Sep 2003 11:04:08 -0700 >Lines: 28 >Organization : United Binary, LLC. >X-Priority: 3 >X-MSMail-Priority: Normal >X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 >Message-ID: <uO************ **@tk2msftngp13 .phx.gbl> >Newsgroups: microsoft.publi c.dotnet.genera l >NNTP-Posting-Host: 130.191.240.187 >Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!tk2 msftngp13.phx.g bl >Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:108001 >X-Tomcat-NG: microsoft.publi c.dotnet.genera l > >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+. >System.Runtime .InteropService s.ExternalExcep tion: A generic erroroccurred >in GDI+. > at System.Drawing. Image.Save(Stri ng filename, ImageCodecInfo encoder, >EncoderParamet ers encoderParams) > at System.Drawing. Image.Save(Stri ng filename, ImageFormat format) > >It's very strange. Most of the time it works without a problem. But >sometimes I get this error. It can happen with the same source imagewhich >just worked previously and will work next time. > >Does anyone know what's causing this? "A generic error" is quietunhelpful >tracking this down. > >Thanks for any help. > >Regards, >Michael > >Michael Kennedy >http://www.unittesting.com > > >
here's wat i found out;:
//-----------------------------------------------------------------------------------------//
Image1.Visible= true;
byte[] picture=picture sInfo.picture;
int newWidth=Conver t.ToInt32(Image 1.Width.Value), newHeight=Conve rt.ToInt32(Imag e1.Height.Value );
System.IO.Memor yStream ms = new System.IO.Memor yStream(picture );
System.Drawing. Image image = System.Drawing. Image.FromStrea m(ms);
try
{
string tempFile = "\\banks.jp g";
System.IO.Path. GetFileName(tem pFile);
image.Save(temp File);
string filePath=System .IO.Path.GetFul lPath(tempFile) ;
Image1.ImageUrl =filePath.ToStr ing();
image.Dispose() ;
}
catch(Exception ex)
{
ex.ToString();
}
//----------the string tempFile = "\\banks.jp g"; points to the C:\ of ur local machine..Make sure the C:\ has ASPNET permission...on ce u do dat ur image appears just like magic
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Fabrizio |
last post by:
Hi,
in my environment i cannot use this sample because the saving process give
me an error : GENERIC ERROR IN GDI+.
Anyone knows what error is and how can I solve this?
thank you!
Fabrizio
fmaltese@nospam.libero.it
|
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 below.
I am running IIS5 on WinXP Pro.
Server Error in '/Chapter04' Application....
|
by: T. Davis |
last post by:
In C#, I am able to successfully stream a TIFF image that comes from a
BLOB field in a database, save it to file, then convert the pages
within TIFF file into jpegs (using GDI+) and display on the web (using
ASP.NET).
However, when I generate the Image object using FromStream (passing in
the MemoryStream containing image bytes), an...
|
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 occurred in GDI+
The line causing the problem is outputImage.Save, but I really don't understand why
...::CODE::.
System.Drawing.Bitmap outputImage...
|
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+.
System.Runtime.InteropServices.ExternalException: A generic error occurred
in GDI+.
at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder,...
| |
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 path of the uploaded image, and resize it with the provided dimensions. My function is below. The current function is returning an error when run...
|
by: news.microsoft.com |
last post by:
Hi guys,
This text looks long and complicate but it is not, and I really really need
some help here.
For the last 24hs I'm trying to resolve this issue (last night I dreamed
|
by: James Wong |
last post by:
Hi everybody,
I'm facing a serious trouble relating to GDI+ generic error. The error
message is "A Generic error occured in GDI+" and the following information
is stored in Excepton object:
System.Drawing.Graphics.CheckErrorStatus(Int32 status)
System.Drawing.Graphics.DrawString(String s, Font font, Brush brush,
RectangleF...
|
by: Adnan Chaudhry |
last post by:
Hi
I'm trying to open, edit and save an animated gif.
When saving frame 2 - I get the following error.
A generic error occured in GDI+ when i reach the following step.
img.SaveAdd(img2, ParameterList);
Code below.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |