java.lang.Object
java.awt.image.ColorConvertOp
- 所有已实现的接口:
-
BufferedImageOp,RasterOp
该类对源图像中的数据执行逐像素颜色转换。生成的颜色值按目标图像的精度进行缩放。颜色转换可以通过ColorSpace对象数组或ICC_Profile对象数组指定。
如果源是具有预乘alpha的BufferedImage,则在颜色转换之前,颜色分量将被alpha分量除以。如果目标是具有预乘alpha的BufferedImage,则在转换后,颜色分量将乘以alpha分量。光栅被视为没有alpha通道,即所有波段都是颜色波段。
如果在构造函数中指定了RenderingHints对象,则颜色渲染提示和抖动提示可用于控制颜色转换。
请注意,源和目标可能是同一个对象。
- 参见:
-
Constructor Summary
ConstructorsConstructorDescriptionColorConvertOp(ColorSpace srcCspace, ColorSpace dstCspace, RenderingHints hints) 从两个ColorSpace对象构造一个新的ColorConvertOp。ColorConvertOp(ColorSpace cspace, RenderingHints hints) 从一个ColorSpace对象构造一个新的ColorConvertOp。ColorConvertOp(ICC_Profile[] profiles, RenderingHints hints) 从一个ICC_Profiles数组构造一个新的ColorConvertOp。ColorConvertOp(RenderingHints hints) 构造一个新的ColorConvertOp,将从源颜色空间转换为目标颜色空间。 -
Method Summary
Modifier and TypeMethodDescriptioncreateCompatibleDestImage(BufferedImage src, ColorModel destCM) 根据此源创建一个大小和波段数正确的零值目标图像。根据此源创建一个大小和波段数正确的零值目标光栅。final BufferedImagefilter(BufferedImage src, BufferedImage dest) 对源BufferedImage进行颜色转换。final WritableRasterfilter(Raster src, WritableRaster dest) 对源光栅中的图像数据进行颜色转换。final Rectangle2DgetBounds2D(BufferedImage src) 给定此源,返回目标的边界框。final Rectangle2DgetBounds2D(Raster src) 给定此源,返回目标的边界框。final ICC_Profile[]返回用于构造此ColorConvertOp的ICC_Profiles数组。final Point2DgetPoint2D(Point2D srcPt, Point2D dstPt) 给定源中的点,返回目标点的位置。final RenderingHints返回此操作使用的渲染提示。
-
Constructor Details
-
ColorConvertOp
构造一个新的ColorConvertOp,将从源颜色空间转换为目标颜色空间。RenderingHints参数可以为null。此Op只能与BufferedImage一起使用,并且将直接从源图像的ColorSpace转换为目标图像的ColorSpace。filter方法的目标参数不能指定为null。- 参数:
-
hints- 用于控制颜色转换的RenderingHints对象,或null
-
ColorConvertOp
从ColorSpace对象构造一个新的ColorConvertOp。RenderingHints参数可以为null。此Op只能与BufferedImage一起使用,当filter方法以null目标参数调用时,此Op主要用于定义由filter方法创建的目标的目标颜色空间。否则,ColorSpace定义了源在转换为目标空间之前要转换的中间空间。- 参数:
-
cspace- 定义目标ColorSpace或中间ColorSpace -
hints- 用于控制颜色转换的RenderingHints对象,或null - 抛出:
-
NullPointerException- 如果cspace为null
-
ColorConvertOp
从两个ColorSpace对象构造一个新的ColorConvertOp。RenderingHints参数可以为null。此Op主要用于在Rasters上调用filter方法,此时两个ColorSpaces定义要在Rasters上执行的操作。在这种情况下,源光栅中的波段数必须与srcCspace中的组件数匹配,并且目标光栅中的波段数必须与dstCspace中的组件数匹配。对于BufferedImages,两个ColorSpaces定义了源在转换为目标空间之前要经过的中间空间。- 参数:
-
srcCspace- 源ColorSpace -
dstCspace- 目标ColorSpace -
hints- 用于控制颜色转换的RenderingHints对象,或null - 抛出:
-
NullPointerException- 如果srcCspace或dstCspace为null
-
ColorConvertOp
从ICC_Profiles数组构造一个新的ColorConvertOp。RenderingHints参数可以为null。配置文件序列可以包括代表颜色空间、代表效果等的配置文件。如果整个序列不表示明确定义的颜色转换,则会抛出异常。对于BufferedImages,如果源BufferedImage的ColorSpace与数组中第一个配置文件的要求不匹配,则首次转换是到适当的ColorSpace。如果目标BufferedImage的ColorSpace不符合数组中最后一个配置文件的要求,则最后一次转换是到目标的ColorSpace。
对于Rasters,源光栅中的波段数必须与数组中第一个配置文件的要求匹配,并且目标光栅中的波段数必须与数组中最后一个配置文件的要求匹配。数组必须至少有两个元素,否则为Rasters调用filter方法将抛出IllegalArgumentException。
- 参数:
-
profiles- ICC_Profile对象数组 -
hints- 用于控制颜色转换的RenderingHints对象,或null - 抛出:
-
IllegalArgumentException- 当配置文件序列未指定明确定义的颜色转换时 -
NullPointerException- 如果profiles为null
-
-
Method Details
-
getICC_Profiles
返回用于构造此ColorConvertOp的ICC_Profiles数组。如果ColorConvertOp不是从这样的数组构造的,则返回null。- 返回:
- 此ColorConvertOp的ICC_Profile对象数组,如果此ColorConvertOp不是使用ICC_Profile对象数组构造的,则返回null。
-
filter
对源BufferedImage进行颜色转换。如果目标图像为null,则将创建一个具有适当ColorModel的BufferedImage。- 指定者:
-
filter在接口BufferedImageOp中 - 参数:
-
src- 要转换的源BufferedImage -
dest- 目标BufferedImage,或null - 返回:
-
从
src颜色转换的dest或一个新的转换的BufferedImage,如果dest为null - 抛出:
-
IllegalArgumentException- 如果dest为null且此op是使用仅接受RenderingHints参数的构造函数构造的,因为操作是不明确的。
-
filter
对源光栅中的图像数据进行颜色转换。如果目标光栅为null,则将创建一个新的光栅。源和目标光栅中的波段数必须满足上面解释的要求。用于创建此ColorConvertOp的构造函数必须提供足够的信息来定义源和目标颜色空间。参见上文。否则,将抛出异常。- 指定者:
-
filter在接口RasterOp中 - 参数:
-
src- 要转换的源Raster -
dest- 目标WritableRaster,或null - 返回:
-
从
src颜色转换的dest或一个新的转换的WritableRaster,如果dest为null - 抛出:
-
IllegalArgumentException- 如果源或目标波段数不正确,源或目标颜色空间未定义,或此op是使用仅适用于BufferedImages操作的构造函数之一构造的。
-
getBounds2D
返回给定此源的目标的边界框。请注意,这将与源的边界框相同。- 指定者:
-
getBounds2D在接口BufferedImageOp中 - 参数:
-
src- 源BufferedImage - 返回:
-
一个
Rectangle2D,即给定指定的src的目标的边界框
-
getBounds2D
返回给定此源的目标的边界框。请注意,这将与源的边界框相同。- 指定者:
-
getBounds2D在接口RasterOp中 - 参数:
-
src- 源Raster - 返回值:
-
一个
Rectangle2D,即给定指定的src时目标的边界框
-
createCompatibleDestImage
创建一个具有正确大小和波段数的零值目标图像,给定此源。- 指定者:
-
createCompatibleDestImage在接口BufferedImageOp中 - 参数:
-
src- 过滤操作的源图像 -
destCM- 目标的ColorModel。如果为null,将使用适当的ColorModel。 - 返回值:
-
一个具有正确大小和波段数的
BufferedImage,来自指定的src - 抛出:
-
IllegalArgumentException- 如果destCM为null,并且此ColorConvertOp创建时没有为目标定义任何ICC_Profile或ColorSpace
-
createCompatibleDestRaster
创建一个具有正确大小和波段数的零值目标Raster,给定此源。- 指定者:
-
createCompatibleDestRaster在接口RasterOp中 - 参数:
-
src- 指定的Raster - 返回值:
-
一个具有正确大小和波段数的
WritableRaster,来自指定的src - 抛出:
-
IllegalArgumentException- 如果此ColorConvertOp创建时没有足够的信息来定义dst和src颜色空间
-
getPoint2D
返回给定源中点的目标点的位置。如果dstPt非null,则将用它来保存返回值。请注意,对于此类,目标点将与源点相同。- 指定者:
-
getPoint2D在接口BufferedImageOp中 - 指定者:
-
getPoint2D在接口RasterOp中 - 参数:
-
srcPt- 指定的源Point2D -
dstPt- 目标Point2D - 返回值:
-
将
dstPt的位置设置为与srcPt相同后的dstPt
-
getRenderingHints
返回此操作使用的渲染提示。- 指定者:
-
getRenderingHints在接口BufferedImageOp中 - 指定者:
-
getRenderingHints在接口RasterOp中 - 返回值:
-
此
ColorConvertOp的RenderingHints对象
-