public class DitherOp extends AbstractBufferedImageOp
DitherOp
provides the dithering capability for reducing
colors of an image to any number of colors. The real number of colors at the
end of color reduction depends on the color profile of the image under
reduction.
Currently the following two dithering algorithm's are supported :
Modifier and Type | Class and Description |
---|---|
static interface |
DitherOp.DitherAlgorithm |
Modifier and Type | Field and Description |
---|---|
static DitherOp.DitherAlgorithm |
DITHER_NONE
Indicate the use of the simple bit width color reduction algorithm
with no further dithering effects.
|
static DitherOp.DitherAlgorithm |
DITHER_SIMPLE_ERROR_CORRECTION
Indicate the use of the simple bit width color reduction algorithm
plus using the simple error correction algorithm.
|
Constructor and Description |
---|
DitherOp(int nCol,
java.awt.Color transparency,
java.awt.Color bgcolor,
DitherOp.DitherAlgorithm algorithm,
java.awt.RenderingHints hints)
Creates a new
DitherOp instance to reduce colors of an
image to the given number of colors. |
Modifier and Type | Method and Description |
---|---|
static java.awt.image.BufferedImage |
convertToIndexed(java.awt.image.BufferedImage src,
int nCol,
java.awt.Color transparency,
java.awt.Color bgcolor,
java.awt.RenderingHints hints)
Converts the source image to an image with IndexColorModel and with
a maximal number of colors.
|
java.awt.image.BufferedImage |
filter(java.awt.image.BufferedImage src,
java.awt.image.BufferedImage dst)
Performs the operation on a BufferedImage.
|
createCompatibleDestImage, getBounds2D, getPoint2D, getRenderingHints
public static final DitherOp.DitherAlgorithm DITHER_NONE
public static final DitherOp.DitherAlgorithm DITHER_SIMPLE_ERROR_CORRECTION
public DitherOp(int nCol, java.awt.Color transparency, java.awt.Color bgcolor, DitherOp.DitherAlgorithm algorithm, java.awt.RenderingHints hints)
DitherOp
instance to reduce colors of an
image to the given number of colors.nCol
- The maximum number of colors to reduce the image to. This
must be higher than 2.transparency
- The Color
of the color to be considered
as transparent. This will be one of the nCol colors if not
null
.bgcolor
- The Color
of the color to be considered
as the background. This will be one of the nCol colors if
not null
.algorithm
- The dithering algorithm to be used.hints
- The RenderingHints for the filter operation. This parameter
may be null
and is not currently used.java.lang.NullPointerException
- if algorithm is null
.java.lang.IllegalArgumentException
- if nCol is less than 2.public static java.awt.image.BufferedImage convertToIndexed(java.awt.image.BufferedImage src, int nCol, java.awt.Color transparency, java.awt.Color bgcolor, java.awt.RenderingHints hints)
src.getColorModel().getMapSize()
) is less than or equal to
the number of colors desired, the source image is returned. Else a new
image is returned.src
- The source image to convert to the IndexColorModel
.nCol
- The maximum number of colors to reduce the image to. This
must be higher than 2.transparency
- The Color
of the color to be considered
as transparent. This will be one of the nCol colors if not
null
.bgcolor
- The Color
of the color to be considered
as the background. This will be one of the nCol colors if
not null
.hints
- The RenderingHints for the filter operation. This parameter
may be null
and is not currently used.IndexColorModel
color model. If
the source image already has the IndexColorModel
and the number of colors are less than or equal to
nCol
the source image is returned else a new
image according to the parameters is returned.java.lang.NullPointerException
- if the source image is null
.java.lang.NullPointerException
- if algorithm is null
.java.lang.IllegalArgumentException
- if nCol is less than 2.public java.awt.image.BufferedImage filter(java.awt.image.BufferedImage src, java.awt.image.BufferedImage dst)
doFilter(BufferedImage, BufferedImage)
to do the actual
filtering operation.
If the color models for the two images do not match, a color conversion into the destination color model will be performed. If the destination image is null, a BufferedImage with an appropriate ColorModel will be created.
Note: The dest image might be clipped if it is not big enough to take the complete resized image.
This method is overwritten to make sure the pixel data is premultiplied with the alpha value to take the real alpha value into account.
filter
in interface java.awt.image.BufferedImageOp
filter
in class AbstractBufferedImageOp
src
- The src image to be resized.dst
- The dest image into which to place the resized image. This
may be null
in which case a new image with the
correct size will be created.null
) or dest
into which the resized src image has been drawn.java.lang.IllegalArgumentException
- if the dest image is the same as the
src image.java.lang.NullPointerException
- if the src image is null
.Copyright © 2010 - 2020 Adobe. All Rights Reserved