473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to resize tiff image ?

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

May 17 '07 #1
1 3457
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(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

May 17 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: alastair | last post by:
Hi, I need to convert a 24-bit RGB TIFF image to an 8-bit RGB TIFF image. I've tried using PIL and the convert() method - this allowed me to convert to an 8-bit grayscale image, close but not...
17
by: PyPK | last post by:
Hi I am looking for a simple tiff Image reader/writer in python.Can anyone point me to the right one.
1
by: Prasad More | last post by:
Hello, I am trying to write a text on Multi-page TIFF image using C# and .NET GDI+. I have written following code to do this. When I execute this code I get "Invalid Parameter User. at...
2
by: Al Reid | last post by:
Is it possible to display an image that is stored on the server as a TIFF image, on an ASP.Net page without the use of an add-in viewer? If so, could someone tell me how to do it? TIA -- Al...
3
by: Andres Corrada-Emmanuel | last post by:
Hello, I have installed PIL 1.1.5 on Windows with Python 2.4. I'm unable to open .tiff images that I can open and view using Windows Explorer. In other words, this simple test fails: import...
1
by: Freedolen | last post by:
Hi, Iam new to this forum. I need to find the given TIFF image is in CMYK or RGB. Though i have checked with Image::Magick, and used: my $img = new Image::Magick; $img->Read("Sample.tif");...
10
by: =?Utf-8?B?UmludSBHb3BhbGFrcmlzaG5hIFBpbGxhaQ==?= | last post by:
Hi, Please help me to write a dll in C# , that will read each pages of a tiff image from a file and a memory stream object ( need two ways) and creatre a new tiff image object.The dll should...
2
by: yogarajan | last post by:
Hi All i want to open tiff image in Internet Explorer <img src="sample.tiff"> it is not working anybody know how can i view the tiff image in IE
1
omerbutt
by: omerbutt | last post by:
hi i am looking for the conversion of the documents of type PDF and word to tiff image single / multi-page using php , i have been searching the net for a long time , there are some scripts related...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.