tags:

views:

214

answers:

2

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

+2  A: 

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

Greg
A: 

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.)

Broam
Rotate trick not needed, these are originals that we control, but thanks for the tip.
mrjoltcola