c# – 如何获取.Net保存此图像?
发布时间:2020-12-15 03:43:12 所属栏目:百科 来源:网络整理
导读:我有 this jpeg,在picasa,photoshop,网络浏览器等开放,但在.Net它只是拒绝工作. Image image = Image.FromFile(@"myimage.jpg"); image.Save(@"myimage2.jpg"); // ExternalException - A generic error occurred in GDI+. 有没有办法在.Net中恢复它,所以我
我有
this jpeg,在picasa,photoshop,网络浏览器等开放,但在.Net它只是拒绝工作.
Image image = Image.FromFile(@"myimage.jpg"); image.Save(@"myimage2.jpg"); // ExternalException - A generic error occurred in GDI+. 有没有办法在.Net中恢复它,所以我可以使用它(我需要调整大小),而不是解决问题在源头? 完整例外细节: source: System.Drawing type: System.Runtime.InteropServices.ExternalException message: A generic error occurred in GDI+. stack trace: at System.Drawing.Image.Save(String filename,ImageCodecInfo encoder,EncoderParameters encoderParams) at System.Drawing.Image.Save(String filename,ImageFormat format) at System.Drawing.Image.Save(String filename) at ConsoleApplication20.Program.Main(String[] args) in C:UserssamDesktopS ourceConsoleApplication20ConsoleApplication20Program.cs:line 16 这个问题在Windows 7上是可重复的. 解决方法
它似乎在Windows XP和Vista上正常工作,但不是Windows 7.
我找到了this issue on Microsoft Connect.它与您的问题不一样,但它看起来非常相似 – 当尝试重新保存JPEG文件时发生ExternalException.目前在16个重复,包括一些意见,问题仍然存在于最终版本. 所以它看起来不是.NET框架中的一个错误,而是Windows 7中的一个错误,特别是GdipSaveImageToStream API中的一个错误. 解决方法,正如其他人所提到的,是强制转换为另一种格式.这就是Marc和Darin的答案正在做的.在JPEG文件中显然有一些“额外的”信息触发Win7中的错误.当您转换为不同的格式或进行位图复制时,该信息(EXIF可能?)被删除. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |