Image.GetThumbnailimage method and quality

I have a problem with Getthumbnailimage. The problem is that the file sizes of a certain size are very blurry and grainy. On msdn says:

The GetThumbnailImage method works well when the requested thumbnail is about 120 x 120 pixels in size. If you request a large thumbnail image (for example, 300 x 300) from an image with a built-in thumbnail, there may be a noticeable loss in quality in the thumbnail image. It might be better to scale the main image (instead of scaling the inline sketch) by calling the DrawImage method.

The problem is that drawimage is similar to window shapes. Is there a way to do this in Webforms? Here is part of my code. Note. I don’t want to receive the thumbnail, someone else wrote this and I just want the actual size displayed.

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

    }
+5
source share
1 answer

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

This method also works in Webforms.

+9
source

All Articles