Solution for generic GDI Error

A generic error occurred in GDI+

I know how frustrating it can be debugging this problem. One case when it occurs is when you try to save an image created from a Stream e.g. using Bitmap Save function.

Few things to consider overcoming this error:

- Make sure you allow the write permission on the folder where image is being saved.

- Release resources after saving the image. For example if you create a Bitmap object from a stream dispose resource by bmp.Dispose() or similar syntax

I will suggest using a try catch finally block like this (I am using C# here):

Bitmap bmp = null; 

try

{

     bmp = new Bitmap(myPostedFile.InputStream, false);

    //save image, do things here 

}

catch

{

}

finally

{

    if (bmp != null)
    {
        bmp.Dispose();
    } 

Was it Enough to Solve this Error?

In my case it wasn't able to solve the problem.

Solution 

Redirect after every the save reloading the page again as fresh. This way it will make sure all the resources being hold will be released and reloaded. Sounds stupid right? In my case it solved the problem. 

Example C# Redirect Code: Response.Redirect("MyPage.aspx",false); 

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: WebCosmo
Posted on: 12/24/2007 at 6:12 AM
Categories: Programming / Coding
E-mail |  Stumble it! |  Propeller it! |  Digg it! |  del.icio.us |  Technorati
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

Related posts

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

Wednesday, December 03, 2008 1:14 PM