public class ColorConvertOp extends Object implements BufferedImageOp, RasterOp
If the source is a BufferedImage with premultiplied alpha, the color components are divided by the alpha component before color conversion. If the destination is a BufferedImage with premultiplied alpha, the color components are multiplied by the alpha component after conversion. Rasters are treated as having no alpha channel, i.e. all bands are color bands.
If a RenderingHints object is specified in the constructor, the color rendering hint and the dithering hint may be used to control color conversion.
Note that Source and Destination may be the same object.
Constructor and Description |
---|
ColorConvertOp(ColorSpace srcCspace,
ColorSpace dstCspace,
RenderingHints hints)
Constructs a new ColorConvertOp from two ColorSpace objects.
|
ColorConvertOp(ColorSpace cspace,
RenderingHints hints)
Constructs a new ColorConvertOp from a ColorSpace object.
|
ColorConvertOp(ICC_Profile[] profiles,
RenderingHints hints)
Constructs a new ColorConvertOp from an array of ICC_Profiles.
|
ColorConvertOp(RenderingHints hints)
Constructs a new ColorConvertOp which will convert
from a source color space to a destination color space.
|
Modifier and Type | Method and Description |
---|---|
BufferedImage |
createCompatibleDestImage(BufferedImage src,
ColorModel destCM)
Creates a zeroed destination image with the correct size and number of
bands, given this source.
|
WritableRaster |
createCompatibleDestRaster(Raster src)
Creates a zeroed destination Raster with the correct size and number of
bands, given this source.
|
BufferedImage |
filter(BufferedImage src,
BufferedImage dest)
ColorConverts the source BufferedImage.
|
WritableRaster |
filter(Raster src,
WritableRaster dest)
ColorConverts the image data in the source Raster.
|
Rectangle2D |
getBounds2D(BufferedImage src)
Returns the bounding box of the destination, given this source.
|
Rectangle2D |
getBounds2D(Raster src)
Returns the bounding box of the destination, given this source.
|
ICC_Profile[] |
getICC_Profiles()
Returns the array of ICC_Profiles used to construct this ColorConvertOp.
|
Point2D |
getPoint2D(Point2D srcPt,
Point2D dstPt)
Returns the location of the destination point given a
point in the source.
|
RenderingHints |
getRenderingHints()
Returns the rendering hints used by this op.
|
public ColorConvertOp(RenderingHints hints)
hints
- the RenderingHints
object used to control
the color conversion, or null
public ColorConvertOp(ColorSpace cspace, RenderingHints hints)
filter
method is invoked with a destination argument of null.
In that case, the ColorSpace defines the destination color space
for the destination created by the filter method. Otherwise, the
ColorSpace defines an intermediate space to which the source is
converted before being converted to the destination space.cspace
- defines the destination ColorSpace
or an
intermediate ColorSpace
hints
- the RenderingHints
object used to control
the color conversion, or null
NullPointerException
- if cspace is nullpublic ColorConvertOp(ColorSpace srcCspace, ColorSpace dstCspace, RenderingHints hints)
srcCspace
- the source ColorSpace
dstCspace
- the destination ColorSpace
hints
- the RenderingHints
object used to control
the color conversion, or null
NullPointerException
- if either srcCspace or dstCspace is nullpublic ColorConvertOp(ICC_Profile[] profiles, RenderingHints hints)
For BufferedImages, if the ColorSpace of the source BufferedImage does not match the requirements of the first profile in the array, the first conversion is to an appropriate ColorSpace. If the requirements of the last profile in the array are not met by the ColorSpace of the destination BufferedImage, the last conversion is to the destination's ColorSpace.
For Rasters, the number of bands in the source Raster must match the requirements of the first profile in the array, and the number of bands in the destination Raster must match the requirements of the last profile in the array. The array must have at least two elements or calling the filter method for Rasters will throw an IllegalArgumentException.
profiles
- the array of ICC_Profile
objectshints
- the RenderingHints
object used to control
the color conversion, or null
IllegalArgumentException
- when the profile sequence does not
specify a well-defined color conversionNullPointerException
- if profiles is nullpublic final ICC_Profile[] getICC_Profiles()
ICC_Profile
objects of this
ColorConvertOp
, or null
if this
ColorConvertOp
was not constructed with an
array of ICC_Profile
objects.public final BufferedImage filter(BufferedImage src, BufferedImage dest)
filter
in interface BufferedImageOp
src
- the source BufferedImage
to be converteddest
- the destination BufferedImage
,
or null
dest
color converted from src
or a new, converted BufferedImage
if dest
is null
IllegalArgumentException
- if dest is null and this op was
constructed using the constructor which takes only a
RenderingHints argument, since the operation is ill defined.public final WritableRaster filter(Raster src, WritableRaster dest)
filter
in interface RasterOp
src
- the source Raster
to be converteddest
- the destination WritableRaster
,
or null
dest
color converted from src
or a new, converted WritableRaster
if dest
is null
IllegalArgumentException
- if the number of source or
destination bands is incorrect, the source or destination
color spaces are undefined, or this op was constructed
with one of the constructors that applies only to
operations on BufferedImages.public final Rectangle2D getBounds2D(BufferedImage src)
getBounds2D
in interface BufferedImageOp
src
- the source BufferedImage
Rectangle2D
that is the bounding box
of the destination, given the specified src
public final Rectangle2D getBounds2D(Raster src)
getBounds2D
in interface RasterOp
src
- the source Raster
Rectangle2D
that is the bounding box
of the destination, given the specified src
public BufferedImage createCompatibleDestImage(BufferedImage src, ColorModel destCM)
createCompatibleDestImage
in interface BufferedImageOp
src
- Source image for the filter operation.destCM
- ColorModel of the destination. If null, an
appropriate ColorModel will be used.BufferedImage
with the correct size and
number of bands from the specified src
.IllegalArgumentException
- if destCM
is
null
and this ColorConvertOp
was
created without any ICC_Profile
or
ColorSpace
defined for the destinationpublic WritableRaster createCompatibleDestRaster(Raster src)
createCompatibleDestRaster
in interface RasterOp
src
- the specified Raster
WritableRaster
with the correct size and number
of bands from the specified src
IllegalArgumentException
- if this ColorConvertOp
was created without sufficient information to define the
dst
and src
color spacespublic final Point2D getPoint2D(Point2D srcPt, Point2D dstPt)
dstPt
is non-null,
it will be used to hold the return value. Note that
for this class, the destination point will be the same
as the source point.getPoint2D
in interface BufferedImageOp
getPoint2D
in interface RasterOp
srcPt
- the specified source Point2D
dstPt
- the destination Point2D
dstPt
after setting its location to be
the same as srcPt
public final RenderingHints getRenderingHints()
getRenderingHints
in interface BufferedImageOp
getRenderingHints
in interface RasterOp
RenderingHints
object of this
ColorConvertOp
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2016, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.