This works well for me (does a proportional rescale):
/// <summary>
/// Resizes an image using the proper (proportional) ratios.
/// </summary>
public static Image RescaleImage(Image img, int MaxWidth, int
MaxHeight, out int newWidth, out int newHeight)
{
newWidth = int.MinValue;
newHeight = int.MinValue;
double widthRatio = 1;
double heightRatio = 1;
double ratio = 1;
if (img.Width MaxWidth || img.Height MaxHeight)
{
widthRatio = (double)img.Width / (double)MaxWidth;
heightRatio = (double)img.Height / (double)MaxHeight;
ratio = Math.Max(widthRatio, heightRatio);
newWidth = (int)(img.Width / ratio);
newHeight = (int)(img.Height / ratio);
}
else
{
newWidth = img.Width;
newHeight = img.Height;
}
Image NewImage = img.GetThumbnailImage(newWidth, newHeight, new
Image.GetThumbnailImageAbort(GetThumbnailImageAbor tCallback),
System.IntPtr.Zero);
return NewImage;
}
On May 17, 1:52 pm, "Stan SR" <s...@pasdepam.netsunset.comwrote:
Hi,
I have some tiff images that I need to use for pdf files.
I need to resize them, but I get a very bad quality.
I would like to know what is the trick to keep the high quality ?
Here's my current code
private System.Drawing.Image Resize(System.Drawing.Image myPic)
{
System.Drawing.Image myPicOut=null;
int newWidth=myPic.Width/4;
int newHeight= myPic.Height/4;
myPicOut=new Bitmap(newWidth,newHeight);
Graphics g= Graphics.FromImage(myPicOut);
g.InterpolationMode=System.Drawing.Drawing2D.Inter polation.HighQualityBicubic;
g.DrawImage(myPic,0,0,newWidth,newHeight);
myPic.Dispose();
return myPicOut;
}
Thanks for your help
Stan