locked
Generic Error Occured In GDI+ RRS feed

  • Question

  • User-2136304695 posted

    Hi, ALL

       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.

    Many Thanks

    Kered

    Monday, September 14, 2009 4:20 PM

Answers

  • User-1136466523 posted

    Hi,

    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 bm1=(Bitmap)Image.FromFile("doodaa.gif");
    Bitmap bm2=new Bitmap(bm1.Width,bm1.Height);
    Graphics g=Graphics.FromImage(bm2);
    g.DrawImageUnscaled(bm1,0,0);
    //bm2 now contains a non-indexed version of the image.
    //Now draw the X..
    g.DrawLine(blah-blah...);
    g.DrawLine(blah-blah...);
    //get rid of the graphics
    g.Dispose();
    //and save a new gif
    bm2.Save("foobar.gif",ImageFormat.Gif);


     

    Here's the KB for you to refer.

    http://support.microsoft.com/default.aspx?id=814675

    Thanks.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 17, 2009 10:37 PM

All replies

  • User-2136304695 posted

     Hi,

         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 ?

     

    Many Thanks

    Kered 

    Tuesday, September 15, 2009 9:11 AM
  • User-1136466523 posted

    Hi,

    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 bm1=(Bitmap)Image.FromFile("doodaa.gif");
    Bitmap bm2=new Bitmap(bm1.Width,bm1.Height);
    Graphics g=Graphics.FromImage(bm2);
    g.DrawImageUnscaled(bm1,0,0);
    //bm2 now contains a non-indexed version of the image.
    //Now draw the X..
    g.DrawLine(blah-blah...);
    g.DrawLine(blah-blah...);
    //get rid of the graphics
    g.Dispose();
    //and save a new gif
    bm2.Save("foobar.gif",ImageFormat.Gif);


     

    Here's the KB for you to refer.

    http://support.microsoft.com/default.aspx?id=814675

    Thanks.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 17, 2009 10:37 PM
  • User-2136304695 posted

     Hi, 

        Thanks for the reply Nai-Dong Jin, that solved my problem. 

    Kered

    Friday, September 18, 2009 3:39 AM