问题
在显示图片时出现大红叉,偶现问题
查看后台日志记录,出现错误如下
1.
System.OutOfMemoryException: Out of memory.
at System.Drawing.Graphics.CheckErrorStatus(Int32 status)
at System.Drawing.Graphics.DrawImage(Image image, Int32 x, Int32 y, Int32 width, Int32 height)
at System.Drawing.Graphics.DrawImage(Image image, Rectangle rect)
at System.Windows.Forms.PictureBox.OnPaint(PaintEventArgs pe)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
2.
System.Runtime.InteropServices.ExternalException (0x80004005): A generic error occurred in GDI+.
at System.Drawing.Image.RotateFlip(RotateFlipType rotateFlipType)
分析
1.
出现Out of memory.
如果文件没有有效的图像格式,或者如果 GDI+ 不支持文件的像素格式,则此方法将引发 OutOfMemoryException 异常
或者
真的内存不足,软件可能存在频繁刷新
2.
出现A generic error occurred in GDI+.
在执行图片旋转RotateFlip方法时出错
处理
1.
出现Out of memory.
第2种处理方法
2.
出现A generic error occurred in GDI+.
原来的代码
img.RotateFlip(RotateFlipType.Rotate180FlipNone);
picImage.Image = img;
修改后的代码
Bitmap bitmap = new Bitmap(img);
bitmap.RotateFlip(RotateFlipType.Rotate180FlipNone);
picImage.Image = bitmap;
由于出现大红叉是偶现问题,还需要一定时间验证