A generic error occurred in GDI+的解决方案

转自智慧光原文A generic error occurred in GDI+. 解决方法

 

使用image1.RotateFlip(RotateFlipType.Rotate90FlipNone)方法时候,出现错误:

An unhandled exception of type 'System.Runtime.InteropServices.ExternalException' occurred in System.Drawing.dll


Additional information: A generic error occurred in GDI+.


但是如果我在生成这个image类型的image1后直接调用image1.RotateFlip方法就没有问题。


原因:To retain access to the source bits, GDI+ locks any source file, and forces the application to maintain the life of any source stream, for the life of the Bitmap or the Image object.


 

位图和图像的构造函数依赖项

http://support.microsoft.com/?id=814675


解决方法:

 Image tmp = (Image)m_List[0];

   Bitmap tmpbitmap = new Bitmap(tmp);
   tmpbitmap.RotateFlip(RotateFlipType.Rotate90FlipNone);
 Image image1 = tmpbitmap;

 

posted @ 2017-01-12 00:11  wenglabs  阅读(9362)  评论(0编辑  收藏  举报