This works well for me (does a proportional rescale):
/// <summary>
/// Resizes an image using the proper (proportional) ratios.
/// </summary>
public static Image RescaleImage(Im age 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.Wid th / (double)MaxWidt h;
heightRatio = (double)img.Hei ght / (double)MaxHeig ht;
ratio = Math.Max(widthR atio, heightRatio);
newWidth = (int)(img.Width / ratio);
newHeight = (int)(img.Heigh t / ratio);
}
else
{
newWidth = img.Width;
newHeight = img.Height;
}
Image NewImage = img.GetThumbnai lImage(newWidth , newHeight, new
Image.GetThumbn ailImageAbort(G etThumbnailImag eAbortCallback) ,
System.IntPtr.Z ero);
return NewImage;
}
On May 17, 1:52 pm, "Stan SR" <s...@pasdepam. netsunset.comwr ote:
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.D rawing.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.FromIm age(myPicOut);
g.Interpolation Mode=System.Dra wing.Drawing2D. Interpolation.H ighQualityBicub ic;
g.DrawImage(myP ic,0,0,newWidth ,newHeight);
myPic.Dispose() ;
return myPicOut;
}
Thanks for your help
Stan