How to resize tiff image ?

S

Stan SR

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.Interpolation.HighQualityBicubic;
g.DrawImage(myPic,0,0,newWidth,newHeight);
myPic.Dispose();

return myPicOut;

}

Thanks for your help

Stan
 
K

KJ

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(GetThumbnailImageAbortCallback),
System.IntPtr.Zero);
return NewImage;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top