.NET 3.5 web app - C# image scaling on the fly - lower quality on deployed site vs development

旧巷老猫 提交于 2019-12-13 14:23:15

问题


I have a VS 2008, .NET 3.5 targeted MVC.NET app. I am developing on Windows 7 with its IIS, but deploying to a Windows Server 2003 environment with .NET 3.5 SP1 installed.

We have a image scaling action that returns an image from the database in the requested resolution, and converts to PNG on the fly with System.Drawing and System.Drawing.Imaging APIs.

The image served up via the deployed site is 1/2 the size/quality of the one in development. The source image is identical, but requesting via the deployed site results in a 6.35 kb PNG of 154x200, but on development it results in a 12.28 kb PNG of 154x200.

My suspicion is there is some difference in the .NET graphics lib on 3.5 SP1 on Windows server? My app explicitly targets the .NET 3.5 runtime.

      Image image = Image.FromStream(new MemoryStream(document.content));
      MemoryStream memStream = new MemoryStream();
      Bitmap bmp = new Bitmap(image, (int)width, (int)height);
      ImageFormat format = ImageFormat.Png;
      string mimeType = document.mimeType;
      if(document.mimeType == "image/png")
          ; // format = ImageFormat.Png;
      else if (document.mimeType == "image/jpeg")
         format = ImageFormat.Jpeg;
      else if (document.mimeType == "image/gif")
         format = ImageFormat.Gif;
      else if (document.mimeType == "image/tiff")
      {
         format = ImageFormat.Png; // convert tiff to png
         mimeType = "image/png";
      }

      bmp.Save(memStream, format);

HTTP headers are: Development: Cache-Control private Content-Type image/png Server Microsoft-IIS/7.5 X-AspNetMvc-Version 2.0 X-AspNet-Version 2.0.50727 X-Powered-By ASP.NET Date Fri, 05 Mar 2010 19:59:50 GMT Content-Length 12574

Production: Date Fri, 05 Mar 2010 20:02:58 GMT Server Microsoft-IIS/6.0 X-Powered-By ASP.NET X-AspNet-Version 2.0.50727 X-AspNetMvc-Version 2.0 Cache-Control private Content-Type image/png Content-Length 6514


回答1:


Maybe you need to set the pixel format or other options that you're just using the default value for: http://www.codeproject.com/KB/GDI-plus/imageresize.aspx




回答2:


Defaults are likely different, which is somewhat odd. Try explicitly specifying color depth as others have said.

Also do the rotate trick to remove thumbnails. (Flip the image by 180 degrees twice. .NET strips the thumbnails on rotate.)



来源:https://stackoverflow.com/questions/2389213/net-3-5-web-app-c-sharp-image-scaling-on-the-fly-lower-quality-on-deployed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!