我怎样才能得到净保存该图像?图像

由网友(19.悸)分享简介:我有这个JPEG ,在Picasa中,软件,网络浏览器等打开罚款但在净它只是拒绝工作。 I have this jpeg, that opens fine in picasa, photoshop, web browser etc. but in .Net it just refuses to work. Image...

我有这个JPEG ,在Picasa中,软件,网络浏览器等打开罚款但在净它只是拒绝工作。

I have this jpeg, that opens fine in picasa, photoshop, web browser etc. but in .Net it just refuses to work.

 Image image = Image.FromFile(@"myimage.jpg");
 image.Save(@"myimage2.jpg");
 // ExternalException - A generic error occurred in GDI+. 

有没有办法恢复它在.net中,所以我可以用它(我需要调整它的大小)工作,没有从源头上解决这个问题?

Is there any way to recover it in .Net so I can work with it (I need to resize it), without fixing the problem at the source?

完整异常详细信息:


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。

This issue is reproducible on Windows 7.

推荐答案

这似乎很好地工作在Windows XP和Vista,而不是Windows 7操作系统。

It seems to work fine on Windows XP and Vista, but not Windows 7.

我能找到这个问题在Microsoft Connect上。这不等同于您的问题,但它看起来的非常的相似 - 一个 ExternalException 试图重新保存为JPEG文件时发生的。目前,在16 repros包括一些意见,该问题仍然存在于最终版本。

I was able to find this issue on Microsoft Connect. It's not identical to your issue but it looks very similar - an ExternalException occurring when trying to resave a JPEG file. Currently at 16 repros including some comments that the issue still exists in the final release.

所以看起来不是要在.NET Framework中的一个错误,但是在Windows 7中的错误 - 具体而言, GdipSaveImageToStream API中的错误

So it looks not to be a bug in the .NET Framework, but a bug in Windows 7 - specifically, a bug in the GdipSaveImageToStream API.

解决方法,如其他人所说的,是强制转换为另一种格式。这就是这两个马克和达林的答案都在做。有明显的JPEG文件被触发在Win7的错误一些额外的信息。当您转换成不同的格式或进行位图副本,该信息(EXIF也许?)被淘汰。

The workaround, as others have mentioned, is to force a conversion to another format. That's what both Marc and Darin's answers are doing. There is obviously some "extra" information in the JPEG file that is triggering the bug in Win7. When you convert to a different format or make a bitmap copy, that information (EXIF maybe?) is eliminated.

阅读全文

相关推荐

最新文章