473,803 Members | 3,195 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.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

May 17 '07 #1
1 3489
KJ
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

May 17 '07 #2

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

Similar topics

3
3047
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 exactly what I need :( From what I've read, it doesn't look like I can do what I need in PIL. Does anyone know of another method ?
17
10046
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
16232
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 System.Drawing.Image.Save" error. public void addAnnotationStampOnImage() { string strStamp = Path.GetFileNameWithoutExtension(_ImageFileName); Size dSize; Image iMulti = Image.FromFile(_ImageFileName);
2
3580
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 Reid
3
6673
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 Image im = Image.open('small.tif') with an 'cannot identify image file' error message. I'm able to open .jpg
1
3024
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"); my ($type) = $img->Get("type");
10
10727
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 return the combined tif image object. Thnks in advance Rinu G P
2
3643
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
3665
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 to converting tiff to pdf like imagemagik has but i have been unable to find the (pdf -> tiff) have any one of you gone through this process before , any source to study or any class or library available for this work would be appreciated ...
0
10542
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10309
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10289
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10068
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9119
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7600
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5496
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4274
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.