- java.lang.Object
-
- javax.imageio.ImageTypeSpecifier
-
public class ImageTypeSpecifier extends Object
允许以方便的方式指定图像的格式(特别是其SampleModel和ColorModel)的类。
-
-
Field Summary
Fields Modifier and Type Field 描述 protected ColorModelcolorModelColorModel用作原型。protected SampleModelsampleModelASampleModel用作原型。
-
构造方法摘要
构造方法 Constructor 描述 ImageTypeSpecifier(ColorModel colorModel, SampleModel sampleModel)构造一个ImageTypeSpecifier直接从ColorModel和SampleModel。ImageTypeSpecifier(RenderedImage image)构造一个ImageTypeSpecifier从RenderedImage。
-
方法摘要
所有方法 静态方法 接口方法 具体的方法 Modifier and Type 方法 描述 static ImageTypeSpecifiercreateBanded(ColorSpace colorSpace, int[] bankIndices, int[] bandOffsets, int dataType, boolean hasAlpha, boolean isAlphaPremultiplied)返回带状图像格式的说明符,将使用ComponentColorModel和BandedSampleModel将每个通道存储在单独的阵列中。BufferedImagecreateBufferedImage(int width, int height)根据此对象中体现的规范,创建一个给定宽度和高度的BufferedImage。static ImageTypeSpecifiercreateFromBufferedImageType(int bufferedImageType)返回一个ImageTypeSpecifier,编码一个标准的BufferedImage类型(TYPE_CUSTOM)。static ImageTypeSpecifiercreateFromRenderedImage(RenderedImage image)返回一个ImageTypeSpecifier编码的布局RenderedImage(其可以是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将每个像素组件存储在单独的字节,短或整数中。static ImageTypeSpecifiercreatePacked(ColorSpace colorSpace, int redMask, int greenMask, int blueMask, int alphaMask, int transferType, boolean isAlphaPremultiplied)返回一个打包图像格式的说明符,该格式将使用DirectColorModel和打包的SampleModel来存储单个字节,短或整数的每个像素。booleanequals(Object o)如果给定的Object是ImageTypeSpecifier并且具有与该对象相同的SampleModel和ColorModel,则返回true。intgetBitsPerBand(int band)返回用于表示给定波段的样本的位数。intgetBufferedImageType()返回一个包含从BufferedImage描述图像格式的枚举常量值的int。ColorModelgetColorModel()返回此对象指定的ColorModel。intgetNumBands()返回此对象指定的频带数。intgetNumComponents()返回此对象指定的颜色成分数。SampleModelgetSampleModel()根据此对象中封装的设置,返回SampleModel。SampleModelgetSampleModel(int width, int height)根据封装在此对象内的设置,返回SampleModel。inthashCode()返回此ImageTypeSpecifier的哈希码。
-
-
-
字段详细信息
-
colorModel
protected ColorModel colorModel
ColorModel被用作原型。
-
sampleModel
protected SampleModel sampleModel
ASampleModel用作原型。
-
-
构造方法详细信息
-
ImageTypeSpecifier
public ImageTypeSpecifier(ColorModel colorModel, SampleModel sampleModel)
构造一个ImageTypeSpecifier直接从ColorModel和SampleModel。 主叫方有责任提供兼容的参数。- 参数
-
colorModel- aColorModel。 -
sampleModel- aSampleModel。 - 异常
-
IllegalArgumentException- 如果任一参数是null。 -
IllegalArgumentException- 如果sampleModel与colorModel不兼容。
-
ImageTypeSpecifier
public ImageTypeSpecifier(RenderedImage image)
构造一个ImageTypeSpecifier从RenderedImage。 如果使用BufferedImage使用其中一种工厂方法createFromRenderedImage或createFromBufferedImageType,以获得更准确的结果。- 参数
-
image- aRenderedImage。 - 异常
-
IllegalArgumentException- 如果参数是null。
-
-
方法详细信息
-
createPacked
public static ImageTypeSpecifier createPacked(ColorSpace colorSpace, int redMask, int greenMask, int blueMask, int alphaMask, int transferType, boolean isAlphaPremultiplied)
返回一个打包图像格式的说明符,该格式将使用DirectColorModel和打包的SampleModel来存储单个字节,短或整数的每个像素。- 参数
-
colorSpace- 所需的ColorSpace。 -
redMask- 连续的掩码表示红色通道的位置。 -
greenMask- 连续的掩码表示绿色通道的位置。 -
blueMask- 连续的掩码表示蓝色通道的位置。 -
alphaMask- 连续的掩码表示Alpha通道的位置。 -
transferType- 所需的SampleModel传输类型。 -
isAlphaPremultiplied-true如果颜色通道将被alpha通道预乘。 - 结果
-
一个
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将每个像素组件存储在单独的字节,短或int中。- 参数
-
colorSpace- 所需的ColorSpace。 -
bandOffsets- 表示每个频带的偏移的int的阵列。 -
dataType- 所需的数据类型,作为DataBuffer类的枚举之一。 -
如果需要alpha通道,则为
hasAlpha-true。 -
isAlphaPremultiplied-true如果颜色通道将被alpha通道预乘。 - 结果
-
一个
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- 表示存储每个频带的存储体的阵列ints。 -
bandOffsets-ints的数组,表示其银行中每个频带的起始偏移量。 -
dataType- 所需的数据类型,作为DataBuffer类中的枚举之一。 -
如果需要alpha通道,则为
hasAlpha-true。 -
isAlphaPremultiplied-true如果颜色通道将被alpha通道预乘。 - 结果
-
一个
ImageTypeSpecifier具有所需的特性。 - 异常
-
IllegalArgumentException- 如果colorSpace是null。 -
IllegalArgumentException- 如果bankIndices是null。 -
IllegalArgumentException- 如果bandOffsets是null。 -
IllegalArgumentException- 如果bankIndices和bandOffsets的长度不同。 -
IllegalArgumentException- 如果bandOffsets.length不等于颜色空间分量的数量,如果hasAlpha为true,则加1。 -
IllegalArgumentException- 如果dataType不是合法的DataBuffer.TYPE_*常数之一。
-
createGrayscale
public static ImageTypeSpecifier createGrayscale(int bits, int dataType, boolean isSigned)
返回一个灰度图像格式的说明符,该格式将将给定位深度的像素包装为指定数据类型的数组元素。- 参数
-
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)
返回一个用于灰度加Alpha图像格式的说明符,它将给定位深度的像素包装为指定数据类型的数组元素。- 参数
-
bits- 每个灰度值的位数(1,2,4,8或16)。 -
dataType- 所需的数据类型,作为DataBuffer类中的枚举之一。 -
isSigned-true如果要表示负值。 -
如果亮度通道将被alpha通道预乘,则
isAlphaPremultiplied-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- 如果非nullLUT参数的长度不完全为1 << bits。 -
IllegalArgumentException-如果dataType不是一个DataBuffer.TYPE_BYTE,DataBuffer.TYPE_SHORT,DataBuffer.TYPE_USHORT,或DataBuffer.TYPE_INT。 -
IllegalArgumentException- 如果bits大于给定的dataType的位大小。
-
createFromBufferedImageType
public static ImageTypeSpecifier createFromBufferedImageType(int bufferedImageType)
返回一个ImageTypeSpecifier,它编码一个标准的BufferedImage类型(TYPE_CUSTOM)。- 参数
-
bufferedImageType- 表示标准BufferedImage类型之一的int。 - 结果
-
一个
ImageTypeSpecifier具有所需的特性。 - 异常
-
IllegalArgumentException- 如果bufferedImageType不是标准类型之一,或者等于TYPE_CUSTOM。 - 另请参见:
-
BufferedImage,BufferedImage.TYPE_INT_RGB,BufferedImage.TYPE_INT_ARGB,BufferedImage.TYPE_INT_ARGB_PRE,BufferedImage.TYPE_INT_BGR,BufferedImage.TYPE_3BYTE_BGR,BufferedImage.TYPE_4BYTE_ABGR,BufferedImage.TYPE_4BYTE_ABGR_PRE,BufferedImage.TYPE_USHORT_565_RGB,BufferedImage.TYPE_USHORT_555_RGB,BufferedImage.TYPE_BYTE_GRAY,BufferedImage.TYPE_USHORT_GRAY,BufferedImage.TYPE_BYTE_BINARY,BufferedImage.TYPE_BYTE_INDEXED
-
createFromRenderedImage
public static ImageTypeSpecifier createFromRenderedImage(RenderedImage image)
返回一个ImageTypeSpecifier编码的布局RenderedImage(其可以是BufferedImage)。- 参数
-
image- aRenderedImage。 - 结果
-
一个
ImageTypeSpecifier具有所需的特性。 - 异常
-
IllegalArgumentException- 如果image是null。
-
getBufferedImageType
public int getBufferedImageType()
返回一个包含从BufferedImage描述图像格式的枚举常数值的BufferedImage。- 结果
-
一个
int代表BufferedImage类型。 - 另请参见:
-
BufferedImage,BufferedImage.TYPE_CUSTOM,BufferedImage.TYPE_INT_RGB,BufferedImage.TYPE_INT_ARGB,BufferedImage.TYPE_INT_ARGB_PRE,BufferedImage.TYPE_INT_BGR,BufferedImage.TYPE_3BYTE_BGR,BufferedImage.TYPE_4BYTE_ABGR,BufferedImage.TYPE_4BYTE_ABGR_PRE,BufferedImage.TYPE_USHORT_565_RGB,BufferedImage.TYPE_USHORT_555_RGB,BufferedImage.TYPE_BYTE_GRAY,BufferedImage.TYPE_USHORT_GRAY,BufferedImage.TYPE_BYTE_BINARY,BufferedImage.TYPE_BYTE_INDEXED
-
getNumComponents
public int getNumComponents()
返回此对象指定的颜色成分数。 这是与ColorModel.getNumComponents返回的值相同的值- 结果
- 图像中的组件数量。
-
getNumBands
public int getNumBands()
返回此对象指定的频带数。 这是与SampleModel.getNumBands返回的值相同的值- 结果
- 图像中的乐队数量。
-
getBitsPerBand
public int getBitsPerBand(int band)
返回用于表示给定波段的样本的位数。- 参数
-
band- 要查询的乐队的索引,作为int。 - 结果
- 一个指定位数的int。
- 异常
-
IllegalArgumentException- 如果band为负数或大于最大频带指数。
-
getSampleModel
public SampleModel getSampleModel()
根据封装在此对象内的设置,返回SampleModel。SampleModel的宽度和高度将被设置为任意值。- 结果
-
一个
SampleModel具有任意维度。
-
getSampleModel
public SampleModel getSampleModel(int width, int height)
根据封装在此对象内的设置,返回一个SampleModel。SampleModel的宽度和高度将被设置为提供的值。- 参数
-
width- 返回的所需宽度SampleModel。 -
height- 所需的高度为SampleModel。 - 结果
-
一个给定尺寸的
SampleModel。 - 异常
-
IllegalArgumentException- 如果width或height为负数或零。 -
IllegalArgumentException- 如果width和height的产品大于Integer.MAX_VALUE
-
getColorModel
public ColorModel getColorModel()
返回此对象指定的ColorModel。- 结果
-
一个
ColorModel。
-
createBufferedImage
public BufferedImage createBufferedImage(int width, int height)
根据此对象中体现的规范,创建一个给定宽度和高度的BufferedImage。- 参数
-
width- 返回的所需宽度BufferedImage。 -
height- 所需的高度返回的BufferedImage。 - 结果
-
一个新的
BufferedImage - 异常
-
IllegalArgumentException- 如果width或height为负数或零。 -
IllegalArgumentException- 如果width和height的产品大于Integer.MAX_VALUE,或者如果存储图像所需的数组元素数大于Integer.MAX_VALUE。
-
equals
public boolean equals(Object o)
如果给定的Object是ImageTypeSpecifier并且具有与该对象相同的SampleModel和ColorModel,则返回true。- 重写:
-
equals在Object - 参数
-
o- 要平等比较的Object。 - 结果
-
true如果给定的对象是等效的ImageTypeSpecifier。 - 另请参见:
-
Object.hashCode(),HashMap
-
hashCode
public int hashCode()
返回此ImageTypeSpecifier的哈希码。- 重写:
-
hashCode在Object - 结果
- 此ImageTypeSpecifier的哈希码
- 另请参见:
-
Object.equals(java.lang.Object),System.identityHashCode(java.lang.Object)
-
-