java.lang.Object
javax.imageio.ImageTypeSpecifier
一个允许以方便的方式指定图像格式(特别是其
SampleModel和ColorModel)的类。
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ColorModel要用作原型的ColorModel。protected SampleModel要用作原型的SampleModel。 -
Constructor Summary
ConstructorsConstructorDescriptionImageTypeSpecifier(ColorModel colorModel, SampleModel sampleModel) 直接从ColorModel和SampleModel构造一个ImageTypeSpecifier。ImageTypeSpecifier(RenderedImage image) 从RenderedImage构造一个ImageTypeSpecifier。 -
Method Summary
Modifier and TypeMethodDescriptionstatic ImageTypeSpecifiercreateBanded(ColorSpace colorSpace, int[] bankIndices, int[] bandOffsets, int dataType, boolean hasAlpha, boolean isAlphaPremultiplied) 返回一个用于存储每个通道在单独数组中的ComponentColorModel和BandedSampleModel的分带图像格式的规范。createBufferedImage(int width, int height) 根据此对象中体现的规范创建具有给定宽度和高度的BufferedImage。static ImageTypeSpecifiercreateFromBufferedImageType(int bufferedImageType) 返回一个编码为标准BufferedImage类型之一的ImageTypeSpecifier(除了TYPE_CUSTOM)。static ImageTypeSpecifier返回一个编码为RenderedImage布局的ImageTypeSpecifier(可能是BufferedImage)。static ImageTypeSpecifiercreateGrayscale(int bits, int dataType, boolean isSigned) 返回一个灰度图像格式的规范,将给定位深度的像素打包到指定数据类型的数组元素中。static ImageTypeSpecifiercreateGrayscale(int bits, int dataType, boolean isSigned, boolean isAlphaPremultiplied) 返回一个灰度加Alpha图像格式的规范,将给定位深度的像素打包到指定数据类型的数组元素中。static ImageTypeSpecifiercreateIndexed(byte[] redLUT, byte[] greenLUT, byte[] blueLUT, byte[] alphaLUT, int bits, int dataType) 返回一个索引颜色图像格式的规范,将给定位深度的索引值打包到指定数据类型的数组元素中。static ImageTypeSpecifiercreateInterleaved(ColorSpace colorSpace, int[] bandOffsets, int dataType, boolean hasAlpha, boolean isAlphaPremultiplied) 返回一个交错图像格式的规范,将使用ComponentColorModel和PixelInterleavedSampleModel将每个像素分量存储在单独的字节、short或int中。static ImageTypeSpecifiercreatePacked(ColorSpace colorSpace, int redMask, int greenMask, int blueMask, int alphaMask, int transferType, boolean isAlphaPremultiplied) 返回一个打包图像格式的规范,将使用DirectColorModel和打包的SampleModel将每个像素打包到单个字节、short或int中。boolean如果给定的Object是一个ImageTypeSpecifier,并且具有与此对象相同的SampleModel和ColorModel,则返回true。intgetBitsPerBand(int band) 返回用于表示给定波段样本的位数的位数。int返回包含描述BufferedImage的图像格式的枚举常量值之一的int。返回此对象指定的ColorModel。int返回此对象指定的波段数。int返回此对象指定的颜色分量数。根据此对象封装的设置返回一个基于SampleModel的SampleModel。getSampleModel(int width, int height) 根据此对象封装的设置返回一个基于SampleModel的SampleModel。inthashCode()返回此ImageTypeSpecifier的哈希码。
-
Field Details
-
colorModel
要用作原型的ColorModel。 -
sampleModel
要用作原型的SampleModel。
-
-
Constructor Details
-
ImageTypeSpecifier
直接从ColorModel和SampleModel构造一个ImageTypeSpecifier。调用者有责任提供兼容的参数。- 参数:
-
colorModel- 一个ColorModel。 -
sampleModel- 一个SampleModel。 - 抛出:
-
IllegalArgumentException- 如果任一参数为null。 -
IllegalArgumentException- 如果sampleModel与colorModel不兼容。
-
ImageTypeSpecifier
从RenderedImage构造一个ImageTypeSpecifier。如果使用BufferedImage,应使用createFromRenderedImage或createFromBufferedImageType工厂方法之一,以获得更准确的结果。- 参数:
-
image- 一个RenderedImage。 - 抛出:
-
IllegalArgumentException- 如果参数为null。
-
-
Method Details
-
createPacked
public static ImageTypeSpecifier createPacked(ColorSpace colorSpace, int redMask, int greenMask, int blueMask, int alphaMask, int transferType, boolean isAlphaPremultiplied) 返回一个使用DirectColorModel和打包的SampleModel将每个像素打包到单个字节、short或int中的打包图像格式的规范。- 参数:
-
colorSpace- 所需的ColorSpace。 -
redMask- 表示红色通道位置的连续掩码。 -
greenMask- 表示绿色通道位置的连续掩码。 -
blueMask- 表示蓝色通道位置的连续掩码。 -
alphaMask- 表示alpha通道位置的连续掩码。 -
transferType- 所需的SampleModel传输类型。 -
isAlphaPremultiplied- 如果颜色通道将由alpha通道预乘,则为true。 - 返回:
-
具有所需特性的
ImageTypeSpecifier。 - 抛出:
-
IllegalArgumentException- 如果colorSpace为null。 -
IllegalArgumentException- 如果colorSpace不是TYPE_RGB类型。 -
IllegalArgumentException- 如果没有掩码至少有1位设置。 -
IllegalArgumentException- 如果transferType不是DataBuffer.TYPE_BYTE、DataBuffer.TYPE_USHORT或DataBuffer.TYPE_INT之一。
-
createInterleaved
public static ImageTypeSpecifier createInterleaved(ColorSpace colorSpace, int[] bandOffsets, int dataType, boolean hasAlpha, boolean isAlphaPremultiplied) 返回一个使用ComponentColorModel和PixelInterleavedSampleModel将每个像素分量存储在单独的字节、short或int中的交错图像格式的规范。- 参数:
-
colorSpace- 所需的ColorSpace。 -
bandOffsets- 一个表示每个波段偏移量的int数组。 -
dataType- 所需的数据类型,作为DataBuffer类中的枚举之一。 -
hasAlpha- 如果需要alpha通道,则为true。 -
isAlphaPremultiplied- 如果颜色通道将由alpha通道预乘,则为true。 - 返回:
-
具有所需特性的
ImageTypeSpecifier。 - 抛出:
-
IllegalArgumentException- 如果colorSpace为null。 -
IllegalArgumentException- 如果bandOffsets为null。 -
IllegalArgumentException- 如果dataType不是合法的DataBuffer.TYPE_*常量之一。 -
IllegalArgumentException- 如果bandOffsets.length不等于颜色空间组件数,如果hasAlpha为true,则再加1。
-
createBanded
public static ImageTypeSpecifier createBanded(ColorSpace colorSpace, int[] bankIndices, int[] bandOffsets, int dataType, boolean hasAlpha, boolean isAlphaPremultiplied) 返回一个使用ComponentColorModel和BandedSampleModel将每个通道存储在单独数组中的分带图像格式的规范。- 参数:
-
colorSpace- 所需的ColorSpace。 -
bankIndices- 一个表示每个波段将存储在其中的银行的int数组。 -
bandOffsets- 一个表示每个波段在其银行内的起始偏移量的int数组。 -
dataType- 所需的数据类型,作为DataBuffer类中的枚举之一。 -
hasAlpha- 如果需要alpha通道,则为true。 -
isAlphaPremultiplied- 如果颜色通道将由alpha通道预乘,则为true。 - 返回:
-
具有所需特性的
ImageTypeSpecifier。 - 抛出:
-
IllegalArgumentException- 如果colorSpace为null。 -
IllegalArgumentException- 如果bankIndices为null。 -
IllegalArgumentException- 如果bandOffsets为null。 -
IllegalArgumentException- 如果bankIndices和bandOffsets的长度不同。 -
IllegalArgumentException- 如果bandOffsets.length不等于颜色空间组件数,如果hasAlpha为true。 -
IllegalArgumentException- 如果dataType不是合法的DataBuffer.TYPE_*常量之一。
-
createGrayscale
返回一个灰度图像格式的规范,将给定位深度的像素打包到指定数据类型的数组元素中。- 参数:
-
bits- 每个灰度值的位数(1、2、4、8或16)。 -
dataType- 所需的数据类型,作为DataBuffer类中的枚举之一。 -
isSigned- 如果要表示负值,则为true。 - 返回:
-
具有所需特征的
ImageTypeSpecifier。 - 抛出:
-
IllegalArgumentException- 如果bits不是1、2、4、8或16之一。 -
IllegalArgumentException- 如果dataType不是DataBuffer.TYPE_BYTE、DataBuffer.TYPE_SHORT或DataBuffer.TYPE_USHORT之一。 -
IllegalArgumentException- 如果bits大于给定dataType的位大小。
-
createGrayscale
public static ImageTypeSpecifier createGrayscale(int bits, int dataType, boolean isSigned, boolean isAlphaPremultiplied) 返回一个灰度加透明度图像格式的规范,将给定位深度的像素打包到指定数据类型的数组元素中。- 参数:
-
bits- 每个灰度值的位数(1、2、4、8或16)。 -
dataType- 所需的数据类型,作为DataBuffer类中的枚举之一。 -
isSigned- 如果要表示负值,则为true。 -
isAlphaPremultiplied- 如果亮度通道将被alpha通道预乘,则为true。 - 返回:
-
具有所需特征的
ImageTypeSpecifier。 - 抛出:
-
IllegalArgumentException- 如果bits不是1、2、4、8或16之一。 -
IllegalArgumentException- 如果dataType不是DataBuffer.TYPE_BYTE、DataBuffer.TYPE_SHORT或DataBuffer.TYPE_USHORT之一。 -
IllegalArgumentException- 如果bits大于给定dataType的位大小。
-
createIndexed
public static ImageTypeSpecifier createIndexed(byte[] redLUT, byte[] greenLUT, byte[] blueLUT, byte[] alphaLUT, int bits, int dataType) 返回一个索引颜色图像格式的规范,将给定位深度的索引值打包到指定数据类型的数组元素中。- 参数:
-
redLUT- 包含每个索引的红色值的byte数组。 -
greenLUT- 包含每个索引的绿色值的byte数组。 -
blueLUT- 包含每个索引的蓝色值的byte数组。 -
alphaLUT- 包含每个索引的alpha值的byte数组,或者为null以创建完全不透明的LUT。 -
bits- 每个索引中的位数。 -
dataType- 所需的输出类型,作为DataBuffer类中的枚举之一。 - 返回:
-
具有所需特征的
ImageTypeSpecifier。 - 抛出:
-
IllegalArgumentException- 如果redLUT为null。 -
IllegalArgumentException- 如果greenLUT为null。 -
IllegalArgumentException- 如果blueLUT为null。 -
IllegalArgumentException- 如果bits不是1、2、4、8或16之一。 -
IllegalArgumentException- 如果非null的LUT参数的长度不完全等于1 << bits。 -
IllegalArgumentException- 如果dataType不是DataBuffer.TYPE_BYTE、DataBuffer.TYPE_SHORT、DataBuffer.TYPE_USHORT或DataBuffer.TYPE_INT之一。 -
IllegalArgumentException- 如果bits大于给定dataType的位大小。
-
createFromBufferedImageType
返回一个编码为标准BufferedImage类型之一(除了TYPE_CUSTOM)的ImageTypeSpecifier。- 参数:
-
bufferedImageType- 表示标准BufferedImage类型之一的整数。 - 返回:
-
具有所需特征的
ImageTypeSpecifier。 - 抛出:
-
IllegalArgumentException- 如果bufferedImageType不是标准类型之一,或等于TYPE_CUSTOM。 - 参见:
-
createFromRenderedImage
返回一个编码为RenderedImage的布局的ImageTypeSpecifier(可能是BufferedImage)。- 参数:
-
image- 一个RenderedImage。 - 返回:
-
具有所需特征的
ImageTypeSpecifier。 - 抛出:
-
IllegalArgumentException- 如果image为null。
-
getBufferedImageType
public int getBufferedImageType()返回一个包含描述来自BufferedImage的图像格式的枚举常量值之一的int。- 返回:
-
代表
BufferedImage类型的int。 - 参见:
-
getNumComponents
public int getNumComponents()返回此对象指定的颜色分量数。这与ColorModel.getNumComponents返回的值相同。- 返回:
- 图像中的组件数。
-
getNumBands
public int getNumBands()返回此对象指定的波段数。这与SampleModel.getNumBands返回的值相同。- 返回:
- 图像中的波段数。
-
getBitsPerBand
public int getBitsPerBand(int band) 返回用于表示给定波段样本的位数。- 参数:
-
band- 要查询的波段索引,作为int类型。 - 返回:
- 一个指定位数的int类型。
- 抛出:
-
IllegalArgumentException- 如果band为负数或大于最大波段索引。
-
getSampleModel
返回一个基于此对象封装的设置的SampleModel。SampleModel的宽度和高度将设置为任意值。- 返回:
-
一个具有任意维度的
SampleModel。
-
getSampleModel
返回一个基于此对象封装的设置的SampleModel。SampleModel的宽度和高度将设置为提供的值。- 参数:
-
width- 返回的SampleModel的期望宽度。 -
height- 返回的SampleModel的期望高度。 - 返回:
-
一个具有给定维度的
SampleModel。 - 抛出:
-
IllegalArgumentException- 如果width或height为负数或零。 -
IllegalArgumentException- 如果width和height的乘积大于Integer.MAX_VALUE。
-
getColorModel
返回此对象指定的ColorModel。- 返回:
-
一个
ColorModel。
-
createBufferedImage
根据此对象中体现的规范,创建具有给定宽度和高度的BufferedImage。- 参数:
-
width- 返回的BufferedImage的期望宽度。 -
height- 返回的BufferedImage的期望高度。 - 返回:
-
一个新的
BufferedImage - 抛出:
-
IllegalArgumentException- 如果width或height为负数或零。 -
IllegalArgumentException- 如果width和height的乘积大于Integer.MAX_VALUE,或者如果存储图像所需的数组元素数量大于Integer.MAX_VALUE。
-
equals
如果给定的Object是一个ImageTypeSpecifier,并且具有与此对象相等的SampleModel和ColorModel,则返回true。 -
hashCode
public int hashCode()返回此ImageTypeSpecifier的哈希码。
-