Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Go Picture Crazy: Resize Images Using GDI+

It's tempting to use GDI+'s GetThumbnailImage method when you need to manipulate the size of images in your applications, but you'll pay for it with image degradation. There's a better way. Use the ResizeImage API in this article to do whatever you like with images and never drop a pixel (unless you want to).


advertisement
ne of the many improvements of .NET's GDI+ over its Win32-based predecessor is its high-level image processing API. It's a doddle for Web servers running ASP.NET to stream JPEG data on the fly, and standalone desktop applications also benefit from a good set of methods to load, save, and convert image data from a variety of resources and media. However, just because it's easy to do something with GDI+ doesn't necessarily mean you should use it, and one place you're likely to get stung—sooner or later—is when you try to resize an image.

The System.Drawing.Image and System.Drawing.Bitmap namespaces have every manner of method to manipulate image formats and properties, and bang!—in the middle of both namespaces is one method that looks exactly like what you want:

Image GetThumbnailImage(int thumbWidth, int thumbHeight ...)

Sure enough, pass an Image or a Bitmap to GetThumbnailImage, and you'll get back another image at the dimensions you specified. But you should take a cue from the method's title: What it wants to return you is a thumbnail, not simply a resized image.


You want to manipulate the size of an original image, but the best method provided in GDI+ for doing so is designed to work with embedded thumbnails, not originals, causing poor image quality and lack of control over aspect ratios.


Use the ImageResize class and API to grab and manipulate images based on any property you find convenient.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap