Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image.GetThumbnailimage method and quality

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

    }
like image 931
Jeffrey Easley Avatar asked Aug 26 '11 19:08

Jeffrey Easley


1 Answers

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.

like image 172
Tridus Avatar answered Oct 06 '22 03:10

Tridus