Resizes an image by the specified scale factor, which is applied to both the X and Y dimensions.
static RenderedImage resizeImage(source, scaleFactor)
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 |
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"));
...
© 2008 Sean Kleinjung. All Rights Reserved.