public static Bitmap GetThumbnail(Bitmap source, int maxWidth, int maxHeight)
{
int iHeight = 0;
int iWidth = 0;
iHeight = source.Height;
iWidth = source.Width;
if (source.Width > maxWidth)
{
if (source.Width > source.Height)
{
iWidth = maxWidth;
iHeight = source.Height * maxWidth / source.Width;
}
else
{
iHeight = maxHeight;
iWidth = source.Width * maxHeight / source.Height;
}
}
else if (source.Height > maxHeight)
{
if (source.Width > source.Height)
{
iWidth = maxWidth;
iHeight = source.Height * maxWidth / source.Width;
}
else
{
iHeight = maxHeight;
iWidth = source.Width * maxHeight / source.Height;
}
}
Bitmap dest = new Bitmap(source, iWidth, iHeight);
return dest;
}