BufferedImageOppublic class ResampleOp extends Object implements BufferedImageOp
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:
If your imput image is very large, it's possible to first resample using the very fastBufferedImage image; //... ResampleOp resampler = new ResampleOp(100, 100, ResampleOp.FILTER_TRIANGLE); BufferedImage thumbnail = resampler.filter(image, null);
FILTER_POINT algorithm, then resample to the wanted size,
using a higher quality algorithm:
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 propertyBufferedImage 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);
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.ResampleOp(int,int,int),
ResampleOp(int,int,java.awt.RenderingHints),
BufferedImage,
RenderingHints,
AffineTransformOp| Modifier and Type | Field | Description |
|---|---|---|
static int |
FILTER_BLACKMAN |
Blackman interpolation..
|
static int |
FILTER_BLACKMAN_BESSEL |
Blackman-Bessel interpolation.
|
static int |
FILTER_BLACKMAN_SINC |
Blackman-Sinc interpolation.
|
static int |
FILTER_BOX |
Box interpolation.
|
static int |
FILTER_CATROM |
Catrom interpolation.
|
static int |
FILTER_CUBIC |
Cubic interpolation.
|
static int |
FILTER_GAUSSIAN |
Gaussian interpolation.
|
static int |
FILTER_HAMMING |
Hamming interpolation.
|
static int |
FILTER_HANNING |
Hanning interpolation.
|
static int |
FILTER_HERMITE |
Hermite interpolation.
|
static int |
FILTER_LANCZOS |
Lanczos interpolation.
|
static int |
FILTER_MITCHELL |
Mitchell interpolation.
|
static int |
FILTER_POINT |
Point interpolation (also known as "nearest neighbour").
|
static int |
FILTER_QUADRATIC |
Quadratic interpolation.
|
static int |
FILTER_TRIANGLE |
Triangle interpolation (also known as "linear" or "bilinear").
|
static int |
FILTER_UNDEFINED |
Undefined interpolation, filter method will use default filter.
|
static RenderingHints.Key |
KEY_RESAMPLE_INTERPOLATION |
RenderingHints.Key specifying resampling interpolation algorithm.
|
static Object |
VALUE_INTERPOLATION_BLACKMAN |
|
static Object |
VALUE_INTERPOLATION_BLACKMAN_BESSEL |
|
static Object |
VALUE_INTERPOLATION_BLACKMAN_SINC |
|
static Object |
VALUE_INTERPOLATION_BOX |
|
static Object |
VALUE_INTERPOLATION_CATROM |
|
static Object |
VALUE_INTERPOLATION_CUBIC |
|
static Object |
VALUE_INTERPOLATION_GAUSSIAN |
|
static Object |
VALUE_INTERPOLATION_HAMMING |
|
static Object |
VALUE_INTERPOLATION_HANNING |
|
static Object |
VALUE_INTERPOLATION_HERMITE |
|
static Object |
VALUE_INTERPOLATION_LANCZOS |
|
static Object |
VALUE_INTERPOLATION_MITCHELL |
|
static Object |
VALUE_INTERPOLATION_POINT |
|
static Object |
VALUE_INTERPOLATION_QUADRATIC |
|
static Object |
VALUE_INTERPOLATION_TRIANGLE |
| Constructor | Description |
|---|---|
ResampleOp(int width,
int height) |
Creates a
ResampleOp that will resample input images to the
given width and height, using the default interpolation filter. |
ResampleOp(int width,
int height,
int filterType) |
Creates a
ResampleOp that will resample input images to the
given width and height, using the given interpolation filter. |
ResampleOp(int width,
int height,
RenderingHints hints) |
Creates a
ResampleOp that will resample input images to the
given width and height, using the interpolation filter specified by
the given hints. |
| Modifier and Type | Method | Description |
|---|---|---|
BufferedImage |
createCompatibleDestImage(BufferedImage pInput,
ColorModel pModel) |
|
BufferedImage |
filter(BufferedImage input,
BufferedImage output) |
Re-samples (scales) the image to the size, and using the algorithm
specified in the constructor.
|
Rectangle2D |
getBounds2D(BufferedImage src) |
|
int |
getFilterType() |
Returns the current filter type constant.
|
Point2D |
getPoint2D(Point2D srcPt,
Point2D dstPt) |
|
RenderingHints |
getRenderingHints() |
public static final int FILTER_UNDEFINED
public static final int FILTER_POINT
RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR
and Image.SCALE_REPLICATE).public static final int FILTER_BOX
public static final int FILTER_TRIANGLE
RenderingHints.VALUE_INTERPOLATION_BILINEAR and
Image.SCALE_AREA_AVERAGING).public static final int FILTER_HERMITE
public static final int FILTER_HANNING
public static final int FILTER_HAMMING
public static final int FILTER_BLACKMAN
public static final int FILTER_GAUSSIAN
public static final int FILTER_QUADRATIC
public static final int FILTER_CUBIC
public static final int FILTER_CATROM
public static final int FILTER_MITCHELL
public static final int FILTER_LANCZOS
public static final int FILTER_BLACKMAN_BESSEL
public static final int FILTER_BLACKMAN_SINC
public static final RenderingHints.Key KEY_RESAMPLE_INTERPOLATION
public static final Object VALUE_INTERPOLATION_POINT
FILTER_POINTpublic static final Object VALUE_INTERPOLATION_BOX
FILTER_BOXpublic static final Object VALUE_INTERPOLATION_TRIANGLE
FILTER_TRIANGLEpublic static final Object VALUE_INTERPOLATION_HERMITE
FILTER_HERMITEpublic static final Object VALUE_INTERPOLATION_HANNING
FILTER_HANNINGpublic static final Object VALUE_INTERPOLATION_HAMMING
FILTER_HAMMINGpublic static final Object VALUE_INTERPOLATION_BLACKMAN
FILTER_BLACKMANpublic static final Object VALUE_INTERPOLATION_GAUSSIAN
FILTER_GAUSSIANpublic static final Object VALUE_INTERPOLATION_QUADRATIC
FILTER_QUADRATICpublic static final Object VALUE_INTERPOLATION_CUBIC
FILTER_CUBICpublic static final Object VALUE_INTERPOLATION_CATROM
FILTER_CATROMpublic static final Object VALUE_INTERPOLATION_MITCHELL
FILTER_MITCHELLpublic static final Object VALUE_INTERPOLATION_LANCZOS
FILTER_LANCZOSpublic static final Object VALUE_INTERPOLATION_BLACKMAN_BESSEL
FILTER_BLACKMAN_BESSELpublic static final Object VALUE_INTERPOLATION_BLACKMAN_SINC
FILTER_BLACKMAN_SINCpublic ResampleOp(int width,
int height)
ResampleOp that will resample input images to the
given width and height, using the default interpolation filter.width - width of the re-sampled imageheight - height of the re-sampled imagepublic ResampleOp(int width,
int height,
RenderingHints hints)
ResampleOp that will resample input images to the
given width and height, using the interpolation filter specified by
the given hints.
If using RenderingHints, the hints are mapped as follows:
KEY_RESAMPLE_INTERPOLATION takes precedence over any
standard java.awt hints, and dictates interpolation
directly, see
RenderingHints constants.KEY_INTERPOLATION takes precedence over other hints.
RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR specifies
FILTER_POINTRenderingHints.VALUE_INTERPOLATION_BILINEAR specifies
FILTER_TRIANGLERenderingHints.VALUE_INTERPOLATION_BICUBIC specifies
FILTER_QUADRATICKEY_RENDERING or KEY_COLOR_RENDERING
RenderingHints.VALUE_RENDER_SPEED specifies
FILTER_POINTRenderingHints.VALUE_RENDER_QUALITY specifies
FILTER_MITCHELLwidth - width of the re-sampled imageheight - height of the re-sampled imagehints - rendering hints, affecting interpolation algorithmKEY_RESAMPLE_INTERPOLATION,
RenderingHints.KEY_INTERPOLATION,
RenderingHints.KEY_RENDERING,
RenderingHints.KEY_COLOR_RENDERINGpublic ResampleOp(int width,
int height,
int filterType)
ResampleOp that will resample input images to the
given width and height, using the given interpolation filter.width - width of the re-sampled imageheight - height of the re-sampled imagefilterType - interpolation filter algorithmpublic final BufferedImage filter(BufferedImage input, BufferedImage output)
filter in interface BufferedImageOpinput - The BufferedImage to be filteredoutput - The BufferedImage in which to store the resampled
imageBufferedImage.NullPointerException - if input is nullIllegalArgumentException - if input == output.ResampleOp(int,int,int)public int getFilterType()
public final BufferedImage createCompatibleDestImage(BufferedImage pInput, ColorModel pModel)
createCompatibleDestImage in interface BufferedImageOppublic RenderingHints getRenderingHints()
getRenderingHints in interface BufferedImageOppublic Rectangle2D getBounds2D(BufferedImage src)
getBounds2D in interface BufferedImageOppublic Point2D getPoint2D(Point2D srcPt, Point2D dstPt)
getPoint2D in interface BufferedImageOpCopyright © 2018. All rights reserved.