C#保存图片时提示“GDI+ 中发生一般性错误”

来源:互联网 发布:linux下删除用户 编辑:程序博客网 时间:2024/05/23 00:02
问题:保存图片时有时正常,有时出现如下错误:
 
********** 异常文本 **************
System.Runtime.InteropServices.ExternalException: GDI+ 中发生一般性错误。
   在 System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
   在 System.Drawing.Image.Save(String filename, ImageFormat format)
   在 SelfFilling.XYYT.Business.FrmLogin.ReadCard()
   在 SelfFilling.XYYT.Business.FrmLogin.timer1_Tick(Object sender, EventArgs e)
   在 System.Windows.Forms.Timer.OnTick(EventArgs e)
   在 System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
   在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
 
此问题发生在图片刚刚被窗口的Picture控件使用过,但是使用它的窗口已经关闭。然后打算使用同名图片覆盖此图片的时候,偶尔会出现此错误,再次保存就成功了。所以可能是图片在使用过程中不能修改删除。
 
考虑使用下列方法解决:
方法一:使用的时候创建一个图片的副本,使用副本。
方法二:发现相同的图片,跳过,不必覆盖。
0 0
原创粉丝点击