Since more often than not, you're going to want an image thumbnail that persists aspect ratio, I wrote up a blog post here - http://blog.rileytech.net/post.aspx?id=718af0a2-28be-4b2c-b327-e54680f5d83c and incase for whatever reason the site goes away, here's the code to maintain that aspect ratio (maybe include this in the next .net?)
//start copy from here
const int thumbSize = 100;
private void MakeMeAGoodThumbnail()
{
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap("MyImage.jpg");
int width, height;
//these are just arbitary numbers -- if the image is larger than this, create a 100px max by 100px max thumbnail defined by the constant at the start
if (bmp.Height > 320 || bmp.Width > 240)
{
float percent = DeterminePercentageForResize(bmp.Height, bmp.Width);
float floatWidth = (float)bmp.Width * percent;
float floatHeight = (float)bmp.Height * percent;
width = Convert.ToInt32(floatWidth);
height = Convert.ToInt32(floatHeight);
}
else
{
width = bmp.Width;
height = bmp.Height;
}
System.Drawing.Image thumb = bmp.GetThumbnailImage(width, height, ThumbnailCallback, IntPtr.Zero);
thumb.Save("MyNewImage.jpg");
}
private float DeterminePercentageForResize(int height, int width)
{
int highestValue;
if (height > width)
highestValue = height;
else
highestValue = width;
float percent = (float)thumbSize / (float)highestValue;
if (percent > 1 && percent != 0)
throw new Exception("Percent cannot be greater than 1 or equal to zero");
else
return percent;
}
public bool ThumbnailCallback()
{
return false;
}