Home » Programming / Coding

Solution for generic GDI Error

24 December 2007 356 views No Comment

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);

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.