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 stungsooner or lateris 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
, 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.