.Net ramblings
# Wednesday, 18 July 2007
JPEG Resizing Quality Problems .Net
public static ImageCodecInfo GetEncoderInfo(String mimeType)
int j;
ImageCodecInfo[] encoders;
encoders = ImageCodecInfo.GetImageEncoders();
for(j = 0; j < encoders.Length; ++j)
if(encoders[j].MimeType == mimeType)
return encoders[j];
return null;

public static Bitmap resizeImage(Bitmap originalImage, int max)
// never increase the size of an image from this method because it loses resolution
if(originalImage.Height <= max && originalImage.Width <= max)
return originalImage;

int height, width;
if(originalImage.Width > originalImage.Height)
width = max;
height = (int)(max/((double)originalImage.Width / (double)originalImage.Height));
height = max;
width = (int)(max/((double)originalImage.Height / (double)originalImage.Width));

Bitmap thumb = new Bitmap(originalImage as Image, width, height);
Graphics resizer = Graphics.FromImage(thumb);
resizer.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
resizer.DrawImage(originalImage, 0, 0, width, height);

return thumb;

public static bool ThumbnailCallback()
return false;

this lovely code highlighted in red solved problems i was having with resizing JPEGs using .net.   without the code in red, some images would appear very grainy when reduced in size.  i got this tip from http://forums.asp.net/p/532033/532033.aspx.

Wednesday, 18 July 2007 17:41:41 (GMT Daylight Time, UTC+01:00)  #    Comments [0]  .Net General | .Net Windows Forms

Please login with either your OpenID above, or your details below.
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

[Captcha]Enter the code shown (prevents robots):

Live Comment Preview