Class ResampleOp

java.lang.Object
com.twelvemonkeys.image.ResampleOp
All Implemented Interfaces:
BufferedImageOp

public class ResampleOp extends Object implements BufferedImageOp
Resamples (scales) a BufferedImage to a new width and height, using high performance and high quality algorithms. Several different interpolation algorithms may be specifed in the constructor, either using the filter type constants, or one of the RendereingHints.

For fastest results, use FILTER_POINT or FILTER_BOX. In most cases, FILTER_TRIANGLE will produce acceptable results, while being relatively fast. For higher quality output, use more sophisticated interpolation algorithms, like FILTER_MITCHELL or FILTER_LANCZOS.

Example:

 BufferedImage image;

 //...

 ResampleOp resampler = new ResampleOp(100, 100, ResampleOp.FILTER_TRIANGLE);
 BufferedImage thumbnail = resampler.filter(image, null);
 

If your input image is very large, it's possible to first resample using the very fast FILTER_POINT algorithm, then resample to the wanted size, using a higher quality algorithm:

 BufferedImage verylLarge;

 //...

 int w = 300;
 int h = 200;

 BufferedImage temp = new ResampleOp(w * 2, h * 2, FILTER_POINT).filter(verylLarge, null);

 BufferedImage scaled = new ResampleOp(w, h).filter(temp, null);
 

For maximum performance, this class will use native code, through JMagick, when available. Otherwise, the class will silently fall back to pure Java mode. Native code may be disabled globally, by setting the system property com.twelvemonkeys.image.accel to false. To allow debug of the native code, set the system property com.twelvemonkeys.image.magick.debug to true.

This BufferedImageOp is based on C example code found in Graphics Gems III, Filtered Image Rescaling, by Dale Schumacher (with additional improvments by Ray Gardener). Additional changes are inspired by ImageMagick and Marco Schmidt's Java Imaging Utilities (which are also adaptions of the same original code from Graphics Gems III).

For a description of the various interpolation algorithms, see General Filtered Image Rescaling in Graphics Gems III, Academic Press, 1994.

Version:
$Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/image/ResampleOp.java#1 $
See Also: