Quality Image Resizing with JAI

ThumbMaster Reference: resizeImage

Resizes an image by the specified scale factor, which is applied to both the X and Y dimensions.

Declaration

static RenderedImage resizeImage(source, scaleFactor)

Parameters

source
A RenderedImage object containing the source image that is to be resized.
scaleFactor
The scaling factor to use when resizing the image. For example, to create an image that is half as tall and half as wide, a scaling factor of 0.5 would be used.

Details

The following table contains example image dimensions, and what size image will be created by a call to this method.

Original Size Requested Width New Size
800×800 0.75 600×600
800×800 0.5 400×400
800×800 0.25 200×200

Example Usage

The following example shows how to load an image file, resize it to one-tenth of its original dimensions, and then save it as a new image:

import net.devella.thumbs.ThumbMaster;

...
// read source image from a file
RenderedImage source =
    ImageIO.read(new File("/tmp/source.png"));

// resize the image
RenderedImage result =
    ThumbMaster.resizeImage(source, 0.1F);

// write the image to a new file
ImageIO.write(result, "png", new File("/tmp/result.png"));
...
Example 1: Resizing images using resizeImage

© 2008 Sean Kleinjung. All Rights Reserved.