Image.GetThumbnailimage method and quality

22,371

If you want more control over the quality of what you get (and better quality in particular), take a look at resizing using this method. There's a bit more work involved, but the results are MUCH better then GetThumbnailImage.

This method also works in Webforms.

Share:
22,371
Jeffrey Easley
Author by

Jeffrey Easley

Updated on August 27, 2020

Comments

  • Jeffrey Easley
    Jeffrey Easley over 3 years

    I'm having an issue with Getthumbnailimage. The problem is that file sizes of a certain size display very blurry and grainy. Over at msdn, it says

    The GetThumbnailImage method works well when the requested thumbnail image has a size of about 120 x 120 pixels. If you request a large thumbnail image (for example, 300 x 300) from an Image that has an embedded thumbnail, there could be a noticeable loss of quality in the thumbnail image. It might be better to scale the main image (instead of scaling the embedded thumbnail) by calling the DrawImage method.

    The problem is that drawimage seems to be in windows forms. Is there any way to do this in Webforms? Here's the part of my code. Note: I don't want to get a thumbnail, somebody else wrote this and I just want the actual size displayed, that's all.

    protected void Page_Load(object sender, System.EventArgs e)
    {
    // Put user code to initialize the page here
    ad a=(ad)Session["a"];
         DataView dv=a.AdData.Tables[0].DefaultView;
    dv.RowFilter="ad_nbr=" + Request.QueryString["l"].Trim();
    byte[] MyData= new byte[0];
    MyData =  (byte[])dv[0]["image"];
    System.Web.HttpContext.Current.Response.ContentType = "image/jpeg";     System.Drawing.Image _image = System.Drawing.Image.FromStream(new  stem.IO.MemoryStream( (byte[])dv[0]["image"]) );
    
    System.Drawing.Image _newimage = _image.GetThumbnailImage(_image.Width, _image.Height,    null, new System.IntPtr() );
    
            _newimage.Save( System.Web.HttpContext.Current.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg );
    
        }
    
  • Jeffrey Easley
    Jeffrey Easley over 12 years
    tried plugging that in, I'm not getting anything on my page output now besides html
  • Tridus
    Tridus over 12 years
    That method is going to create the image, you'll have to put it on another page to output the image by itself and then include that with the <img> tag. Here's help on how to do that