Last post Sep 18, 2009 03:39 AM by leeward30
Sep 14, 2009 04:20 PM|leeward30|LINK
I keep getting (Generic Error Occured In GDI+).
Is this a bug of some sort ?.
I upload a image and get it now and again.
I tried a few samples out there to resize images on upload and get the same problem. Can someone give me a clue how to fix this, or some working code please. I would really like a sample with the resizeing of images.
Sep 14, 2009 05:32 PM|SGWellens|LINK
Sep 15, 2009 09:11 AM|leeward30|LINK
Thanks for the reply. So what I need to do to stop this error is as follows.
1. Create a empty image.
2. Open up a image from the file system etc.
3. Assign the empty image to the one from the file system.
4. Close the image from the file system and dispose of it.
5. Get the graphics etc from the new image.
6. Write text on the image, which is what I need to do.
7. Save the image somewhere else.
Will this work ?
Sep 17, 2009 10:37 PM|Nai-Dong Jin - MSFT|LINK
Have you solved the problem with SGWellens' help?
Just to add some comments, that error is caused by the fact that retaining access to the source bits, GDI+ locks any source file, and forces the application to maintain the life of any source stream, for the life of the Bitmap or the Image object.
One workaround is to create Index or Non-Index image, and copy image to a new Bitmap object by using Graphics.DrawImage() method, and then resize the new imaeg object.
See the following snippet:
Bitmap bm2=new Bitmap(bm1.Width,bm1.Height);
//bm2 now contains a non-indexed version of the image.
//Now draw the X..
//get rid of the graphics
//and save a new gif
Here's the KB for you to refer.
Sep 18, 2009 03:39 AM|leeward30|LINK
Thanks for the reply Nai-Dong Jin, that solved my problem.