int oldh = img.Height;
int oldw = img.Width;
int newh,neww;
double h1 = oldh*1.0/h;
double w1 = oldw*1.0/w;
double f = (h1>w1)? h1:w1;
if(f < 1.0)
{
newh = oldh;
neww = oldw;
}
else
{
newh = (int)(oldh/f);
neww = (int)(oldw/f);
}
System.Drawing.Image myThumbnail = img.GetThumbnailImage(neww, newh, myCallback, IntPtr.Zero);
myThumbnail.Save(newfile, System.Drawing.Imaging.ImageFormat.Jpeg);
img.Dispose();
myThumbnail.Dispose();
}
private bool ThumbnailCallback()
{
return false;
}