Meet us at PRINT 19. Chicago, IL. Oct. 3 - 5.
This documentation is for the old version. Go to the latest Graphics Mill docs

Resizing Images

Resizing is one of the most popular operations in image processing. There are a lot of algorithms which produces resized image with various speed and quality. Graphics Mill for .NET implements 12 of them, so can select what is more important for you - high quality or high performance.

To resize an image with Graphics Mill for .NET, you should use Resize transform class. To specify desired dimensions of the resized image, you should use properties Width and Height. If you want to preserve the aspect ratio of the original bitmap, you should specify only one of these properties (the second one must be 0). It will make Graphics Mill for .NET to calculate the second dimension so that aspect ratio would be preserved.

Another important parameter of the Resize transform is an interpolation mode. It specifies how to calculate missing pixels when upsampling, or how to combine several pixels to single one when downsampling. Some interpolation modes works fast, but have lower quality, some ones are working slow, but has high quality. To make resizing algorithms selection easier, you can use values such InterpolationMode enumeration members as LowQuality ( = HighSpeed), MediumQuality ( = MediumSpeed) or HighQuality (LowSpeed) . These values specifies the best algorithm according to your needs. Nevertheless if you would like to get more detailed information about interpolation modes, read topics Comparison of Interpolation Modes and Interpolation Inside.

To be able to use shorter syntax, you can use Resize method of the TransformsProvider returned by the Bitmap. Here is a code example that demonstrates it:

Visual Basic
'Resize image proportionally to width 100
bitmap.Transforms.Resize(100, 0)

'Resize image proportionally to height 100
'bitmap.Transforms.Resize(0, 100)

'Resize image to make both width and height equal 100 
'(don't constrain proportions)
'bitmap.Transforms.Resize(100, 100)
C#
//Resize image proportionally to width 100
bitmap.Transforms.Resize(100, 0);

//Resize image proportionally to height 100
//bitmap.Transforms.Resize(0, 100);

//Resize image to make both width and height equal 100 
//(don't constrain proportions)
//bitmap.Transforms.Resize(100, 100);

A code example which uses Resize is the following:

Visual Basic
Dim resize As New Aurigma.GraphicsMill.Transforms.Resize
'Resize image proportionally to width 100
resize.Width = 100
resize.Height = 0

'Resize image proportionally to height 100
'resize.Width = 0
'resize.Height = 100

'Resize image to make both width and height equal 100 
'(don't constrain proportions)
'resize.Width = 100
'resize.Height = 100

resize.ApplyTransform(bitmap)
C#
Aurigma.GraphicsMill.Transforms.Resize resize =
    new Aurigma.GraphicsMill.Transforms.Resize();
//Resize image proportionally to width 100
resize.Width = 100;
resize.Height = 0;

//Resize image proportionally to height 100
//resize.Width = 0;
//resize.Height = 100;

//Resize image to make both width and height equal 100 
//(don't constrain proportions)
//resize.Width = 100;
//resize.Height = 100;

resize.ApplyTransform(bitmap);

This code demonstrates using of interpolation modes:

Visual Basic
'Resize image proportionally to width 100
bitmap.Transforms.Resize(800, 0, _
 Aurigma.GraphicsMill.Transforms.InterpolationMode.HighQuality)
C#
//Resize image proportionally to width 100
bitmap.Transforms.Resize(800, 0, 
    Aurigma.GraphicsMill.Transforms.InterpolationMode.HighQuality);

Scale-to-gray resizing of the indexed bitmaps

Resizing of indexed images (both bitone and color ones) as usual causes problems, because we cannot use interpolation for 1 bit per pixel images. Only nearest neighbour algorithm (the lowest quality one) can be used in this case. The figure below demonstrates this fact:

Nearest neighbour interpolation sample

To resolve this problem, and produce much more acceptable result, the technique, called scale-to-gray, is used. The idea is to convert image into grayscale pixel format (for bitone 1-bit image) and apply more smart interpolation algorithms. Here is a result which Graphics Mill for .NET produces using scale-to-gray algorithm:

Scale-to-gray interpolation sample

The similar technique can be used for color indexed images (4-bit or 8-bit palette-based bitmaps).

To be enable to use scale-to-gray zoom (or scale-to-color) you can use ScaleToGray (the same as ScaleToColor), MediumQuality, or HighQuality InterpolationMode enumeration members as it is described in above paragraph. If you want to enable scale-to-gray in Windows Forms control BitmapViewer, modify the property ZoomQuality.

If you need to resize in order to get the image thumbnails, we recommend you to consider means described in the article Working with Files.