A generic error occurred in GDI+

If you get this error in C# when you’re calling Bitmap.Save(path), it’s most likely a permissions error. Check your save path and make sure the calling app has permissions to save there.

UPDATE: I also got this error today when trying to save a Bitmap on top of an existing Bitmap. Not sure if the target bitmap was marked as read-only or not (I don”t think so).

Technorati Tags: ,
Advertisements

3 Responses to “A generic error occurred in GDI+”


  1. 1 Karl Lilje May 1, 2008 at 1:12 am

    GDI+ keeps a lock on the file for the lifetime of the Bitmap,
    so if you load a file, and try and save it again, you will receive this error.
    (The reason is it decompresses on demand, which is a good thing for very large images or web images)

    To prevent the Generic Bitmap Error:
    Copy the Bitmap to a new bitmap, and Dispose the original Bitmap object after loading it. The file lock is now removed.

    Cheers
    Karl

  2. 2 Leonardo September 10, 2008 at 3:41 am

    I’m cloning and disposing the bitmap but still can’t overwrite the file it was read from . Very sad.
    Thanks for your help
    Leo

  3. 3 Greg October 29, 2008 at 5:19 pm

    Rather fed up with this right now – getting thoroughly inconsistent behaviour. Won’t even save an image newly created from scratch with no reference to any files…

    Not particularly impressed with the behaviour, but the typical MS ‘An error occurred but we won’t tell you what’ message is far from helpful!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s





%d bloggers like this: