Wednesday, November 14, 2007

System.Drawing.Image.Save() results in ArgumentException: "Parameter is not valid"

If you are using the .NET Image.Save() method to save an image, and you receive an ArgumentException with the message "Parameter is not valid," you probably spent a while examining the parameters you were passing into the Save() call, right? You probably banged your head against the wall and said, "Dear GOD, please tell me WHICH PARAMETER is not valid!"

Unfortunately, the error message is completely unhelpful, and you are seeing it because you had a brain fart. You have called Dispose() on the image object before you tried to Save() it.

If this helps you, please comment on this post, thanks.

7 comments:

bo2bo2 said...

i absolutely have not it's a brand new object and it still throws that exception on a specific image format or something

Khaled Moawad said...

THANKS A MILLION... IT REALLY WORKS.

DaveC said...

Yep it worked. Now I get "A generic error occurred in GDI+"

...sigh

Anonymous said...

thank you :)

Anonymous said...

Thanks!

Anonymous said...

Thank you, yes, forgotten about the dispose.

Derek said...

I love you so much for this - thanks!