locked
Is this the best thumbnails that GDI+ can produce? Pics included aswell as code RRS feed

  • Question

  • User-1171398350 posted

    As you can see below In ,InterpolationMode,SmoothingMode and CompositingQuality are set to the highest values.
    Encode quality is also set to 100.
    As you can see from the pictures located here (link to pics),  the thumbnail quality is good but its not excellent.
    At the above page there are 3 photos, 1 is the original (link), 1 is the result of the code below (link)and the last photo is a thumbnail whose quality Im try to achieve(link). I think that thumbnail was produced using ImageMagick. There is very noticeable difference between the thumbnail generated by the code below(fuzzy.jpg) and  the thumbnail priduced by imageMagick(great.jpg).

    Is there anything I can do to get that desired quality? Is there an error in the code somewhere? If not, perhaps you can recommend a paid component?
    Thankyou for any help.


    //Code/////////////////////////////////////////////////////////
    int DestinationWidth=500;
       int DestinationHeight=375;
       
       string s = "c:\\Temp\\thumb\\y.jpg";
       Bitmap imgOriginal = new Bitmap(s);
       Bitmap imgResized = new Bitmap(DestinationWidth, DestinationHeight);
       Graphics g = Graphics.FromImage(imgResized);
       g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
       g.SmoothingMode= SmoothingMode.HighQuality;
       g.CompositingQuality= CompositingQuality.HighQuality;
       g.DrawImage(imgOriginal, new Rectangle(0, 0, imgResized.Width, imgResized.Height), 0, 0, imgOriginal.Width, imgOriginal.Height, GraphicsUnit.Pixel);
       g.Dispose();
       ImageCodecInfo[] icf = ImageCodecInfo.GetImageEncoders();
       EncoderParameters encps = new EncoderParameters();
       EncoderParameter encp = new EncoderParameter(Encoder.Quality,100L);
       encps.Param[0] = encp;
       ImageCodecInfo[] arrayICI = ImageCodecInfo.GetImageEncoders();
       ImageCodecInfo jpegICI=null;
       
       for (int x = 0; x <= arrayICI.Length - 1; x++)
       {
        if ( (arrayICI[x].FormatDescription.Equals("JPEG")) )
        {
         jpegICI = arrayICI[x];
         goto exitForStatement0;
        }
       }
       exitForStatement0: ;
       if (!(jpegICI == null))
       {
        string filenamesave;
        imgResized.Save("c:\\Temp\\thumb\\y-thumbnail.jpg", jpegICI, encps);
       }

    imgResized.Dispose();

    Friday, April 15, 2005 3:44 PM

All replies

  • User1109032460 posted
    I have absolutely no idea if it will make the slightest bit of difference, but have you considered using the Bitmap's GetThumbnailImage method to extract the thumbnail? I have no idea if will make a difference to the quality, but it should save you a load of code and because the Graphics.DrawImage and Image.GetThumbnailImage go through different code paths (they hit different methods in the unmanaged library) you might see a difference in output.
    Friday, April 15, 2005 7:15 PM
  • User-1171398350 posted

    The first thing I did was try what you suggested. I found that the quality of the GetThumbnailImage was very poor. Its much worse than the result from the code above.

    Thanks for the suggestion though, can anyonelse offer any suggestions?

    Friday, April 15, 2005 7:35 PM
  • User1109032460 posted
    Sorry about that.
    Friday, April 15, 2005 8:19 PM
  • User-95607119 posted
    GetThumbnailImage extracts thumbnail from JPG file if  there is one. By example some cameras save pictures this way. Now, if you take this thumbnail and you resize it larger then of course you will get image with bad quality.
    Sunday, April 17, 2005 5:02 AM