简体   繁体   中英

Invalid parameter when saving bitmap

When I run this code:

Bitmap img = new Bitmap(200, 200);
img.Dispose();
img.Save("somefilename.png", ImageFormat.Png);

I get an error saying that I have an invalid parameter at img.Save . I've searched about this and I do not know what is wrong.

PS: Sorry for my bad english.

Thanks in advance!

I'm pretty sure Dispose release all resources for an image and you're not meant to try do anything with it after that point.

From the documentation :

Call Dispose when you are finished using the Image. The Dispose method leaves the Image in an unusable state.

Try reversing the order of your statements. You Dispose the object and then try to call the save method. Dispose releases all resources and makes the image unusable.

Read up on the Dispose method here

Bitmap img = new Bitmap(200, 200);
img.Save("somefilename.png", ImageFormat.Png);
img.Dispose();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM