Saving An image,A generic error occurred in GDI+

后端 未结 2 1403
旧巷少年郎
旧巷少年郎 2021-01-20 05:32

i get an

A generic error occurred in GDI+

exception when I call img.Save(path, jpegCodec, encoderParams);
here

2条回答
  •  深忆病人
    2021-01-20 06:15

    As long as the image object exists that was created by loading the image from the file, the file is in use. You can't save an image with the same name while the file is in use.

    Instead of using Image.FromFile to load the image, open a file stream and use Image.FromStream to create the image, then close the file stream. That way the file is no longer in use, and you can replace it.

提交回复
热议问题