简体   繁体   English

某些图像无法在Windows Server 2008上加载

[英]Some images fails to load on Windows Server 2008

I have an application running on a Windows Server 2008, that is processing uploaded images. 我有一个在Windows Server 2008上运行的应用程序,正在处理上传的图像。 Currently it successfully processes about 8000 images per day, creating 11 different sizes of each image. 目前,它每天成功处理大约8000张图像,每个图像创建11种不同尺寸。

The problem that I have is that sometimes the application fails to load some images, I get the error "System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.". 我的问题是,有时应用程序无法加载某些图像,但出现错误“ System.Runtime.InteropServices.ExternalException:GDI +中发生一般错误”。

The upload only accepts files with a JPEG extension (jpg/jpeg/jpe) or with a JPEG MIME type, and from what I can tell those images are really JPEG images. 上载仅接受JPEG扩展名(jpg / jpeg / jpe)或JPEG MIME类型的文件,据我所知,这些图像实际上是JPEG图像。 If I look at the image file in windows explorer on the server, it can successfully extract the thumbnail from the file, but if I try to open it, I get the error message "This is not a valid bitmap file, or it's format is not currently supported." 如果在服务器上的Windows资源管理器中查看图像文件,它可以成功从文件中提取缩略图,但是如果尝试打开它,则会收到错误消息“这不是有效的位图文件,或者其格式为目前不支持。” from Paint. 从Paint。

If I copy the image to my own computer, running Windows 7, there is no problem opening the image. 如果将映像复制到运行Windows 7的计算机上,则打开映像没有问题。 It works in Paint, Windows Photo Viewer, Adobe Bridge, and Photoshop. 它适用于Paint,Windows Photo Viewer,Adobe Bridge和Photoshop。 If I try to load the image using Image.FromStream the same way as in the application running on the server, it loads just fine. 如果我尝试使用Image.FromStream加载图像,就像在服务器上运行的应用程序中加载图像一样,它将很好地加载。 (I have copied the file back to the server, and it still doesn't work, so there is nothing in the copying process that changes it.) (我已将文件复制回服务器,但仍然无法正常工作,因此复制过程中没有任何更改。)

When I look at the image information in Bridge, I see that the images are created using Picasa 3.0, but other than that I can't see anything special about them. 当我在Bridge中查看图像信息时,我看到这些图像是使用Picasa 3.0创建的,但除此之外,我看不到任何特殊的图像。 I haven't yet found anyone having the same problem, or any known problems like this with the Picasa application. 我还没有发现有人遇到相同的问题,或者Picasa应用程序有类似的已知问题。

Has anyone had any similar problem, or know if there is something special about images created using Picasa? 是否有人遇到过类似的问题,或者是否知道使用Picasa创建的图像有什么特别之处? Is there any image codec that needs installing on the server to handle all kinds of JPEG images? 是否需要在服务器上安装任何图像编解码器来处理各种JPEG图像?

Here is an example of an image that doesn't load on the server: gdi-example.jpg (192 kB). 以下是未在服务器上加载的图像的示例: gdi-example.jpg (192 kB)。

From Experts exchange I got an example using a BitmapImage object to load the image and resave it to a MemoryStream. 从专家交流中,我得到了一个使用BitmapImage对象加载图像并将其重新保存到MemoryStream的示例。 The BitmapImage can for some reason load the images that the Bitmap object can't. 由于某些原因,BitmapImage可以加载Bitmap对象无法加载的图像。

I also had to load the data from the file and feed it to the BitmapImage as a MemoryStream, so that it wouldn't lock the file. 我还必须从文件中加载数据,并将其作为MemoryStream馈入BitmapImage,以便它不会锁定文件。

So, this is the final code (sans some logging) that I use now: 因此,这是我现在使用的最终代码(没有日志记录):

using WpfImaging = System.Windows.Media.Imaging;
...

byte[] data = File.ReadAllBytes(FileName);

Image master;
using (MemoryStream source = new MemoryStream(data)) {
  var img = new WpfImaging.BitmapImage();
  img.BeginInit();
  img.StreamSource = source;
  img.EndInit();
  WpfImaging.BmpBitmapEncoder encoder = new WpfImaging.BmpBitmapEncoder();
  using (MemoryStream m = new MemoryStream()) {
    encoder.Frames.Add(WpfImaging.BitmapFrame.Create(img));
    encoder.Save(m);
    master = new Bitmap(m);
  }
}

I think it must be something in the EXIF header info generated by Picasa. 我认为这一定是Picasa生成的EXIF标头信息中的内容。 I was having the same problem - processing thousands of images, but occasionally a few don't want to process. 我遇到了同样的问题-处理成千上万张图像,但偶尔有一些不想处理。 I used the cloning fix here: How can I get .Net to save this image? 我在这里使用了克隆修复程序: 如何获取.Net来保存此图像?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM