gdi+ 中发生一般性错误

互联网所找到的相关方法:在开发.NET应用中,使用 System.Drawing.Image.Save 方法而导致“GDI+ 中发生一般性错误”的发生,通常有以下几种原因:

  1. 相应的帐户没有写权限。 解决方法:赋予 NETWORK SERVICE 帐户以写权限。
  2. 指定的物理路径不存在。 解决方法: 在调用 Save 方法之前,先判断目录是否存在,若不存在,则创建。 if (!Directory.Exists(dirpath)) Directory.CreateDirectory(dirpath);
  3. 保存的文件已存在并因某种原因被锁定。 解决方法: 重启IIS,解除锁定。并在代码中使用 using 语句,确保释放 Image 对象所使用的所有资源。

遇到的情况 4.存在被使用路径时,注释处为释放资源可解决

Threading.Thread.Sleep(300)
        bmp.RotateFlip(Rotate1)
        ‘’Bmp1 = New Bitmap(Inbmp.Width, bmp.Height)
        Dim g As Graphics = Graphics.FromImage(Bmp1)
        ‘’g.DrawImage(bmp, New Point)
        bmp.Dispose()
        Bmp1 = bmp.Clone
        ‘’PicboxControl1.SetImage(Bmp1)

5.内存爆满问题 自身是做相机拍摄,因为相机返回的像素过大导致内存爆满。先看看自己相机的返回图像多大,与自身系统是否能够带的动。

经验分享 程序员 微信小程序 职场和发展