|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectjava.awt.image.SampleModel
java.awt.image.ComponentSampleModel
public class ComponentSampleModel
此类表示按每个像素样本占用 DataBuffer 中一个数据元素的方式存储的图像数据。它可存储 N 个样本,这 N 个样本可通过 N 个独立的数据数组元素组成像素。不同的 band 可能位于 DataBuffer 的不同存储单元中。由于提供了存取方法,因此可以直接对图像数据进行操作。此类可以支持不同类型的交错,如 band 交错、扫描行交错和像素交错等。像素间距是同一扫描行上同一 band 的两个样本之间的数据数组元素数。扫描行间距是给定样本与下一扫描行的同一列中对应样本之间的数据数组元素数。band 偏移量表示从保存每个 band 的 DataBuffer 存储单元第一个数据数组元素到 band 第一个样本之间的数据数组元素数。band 从 0 到 N-1 进行编号。此类可以表示以下图像数据:每个样本都是可以按 8、16 或 32 位存储的无符号整数的图像数据(分别使用 DataBuffer.TYPE_BYTE、DataBuffer.TYPE_USHORT 或 DataBuffer.TYPE_INT)、每个样本都是可以按 16 位存储的有符号整数的图像数据(使用 DataBuffer.TYPE_SHORT)、每个样本都是有符号 float 和 double 量的图像数据(分别使用 DataBuffer.TYPE_FLOAT 或 DataBuffer.TYPE_DOUBLE)。所有给定的 ComponentSampleModel 样本都是以同样的精度存储的。所有间距和偏移量必须为非负数。此类支持 TYPE_BYTE、TYPE_USHORT、TYPE_SHORT、TYPE_INT、TYPE_FLOAT 和 TYPE_DOUBLE。
PixelInterleavedSampleModel,
BandedSampleModel| 字段摘要 | |
|---|---|
protected int[] |
bandOffsets
数据数组元素中所有 band 的偏移量。 |
protected int[] |
bankIndices
各个存储图像数据 band 的存储单元的索引。 |
protected int |
numBands
此 ComponentSampleModel 中的 band 数量。 |
protected int |
numBanks
此 ComponentSampleModel 中的存储单元数量。 |
protected int |
pixelStride
由此 ComponentSampleModel 所描述的图像数据区域的像素间距(以数据数组元素表示)。 |
protected int |
scanlineStride
由此 ComponentSampleModel 所描述的图像数据区域的行间距(以数据数组元素表示)。 |
| 从类 java.awt.image.SampleModel 继承的字段 |
|---|
dataType, height, width |
| 构造方法摘要 | |
|---|---|
ComponentSampleModel(int dataType,
int w,
int h,
int pixelStride,
int scanlineStride,
int[] bandOffsets)
构造具有指定参数的 ComponentSampleModel。 |
|
ComponentSampleModel(int dataType,
int w,
int h,
int pixelStride,
int scanlineStride,
int[] bankIndices,
int[] bandOffsets)
构造具有指定参数的 ComponentSampleModel。 |
|
| 方法摘要 | |
|---|---|
SampleModel |
createCompatibleSampleModel(int w,
int h)
创建具有指定宽度和高度的 ComponentSampleModel。 |
DataBuffer |
createDataBuffer()
创建对应于此 ComponentSampleModel 的 DataBuffer。 |
SampleModel |
createSubsetSampleModel(int[] bands)
创建具有此 ComponentSampleModel 的 band 子集的新 ComponentSampleModel。 |
boolean |
equals(Object o)
指示其他某个对象是否与此对象“相等”。 |
int[] |
getBandOffsets()
返回所有 band 的 band 偏移量。 |
int[] |
getBankIndices()
返回所有 band 的存储单元索引。 |
Object |
getDataElements(int x,
int y,
Object obj,
DataBuffer data)
以 TransferType 类型基本数组形式返回单个像素的数据。 |
int |
getNumDataElements()
返回使用 getDataElements(int, int, Object, DataBuffer) 和 setDataElements(int, int, Object, DataBuffer) 方法传输像素所需的数据元素的数量。 |
int |
getOffset(int x,
int y)
获取像素 (x,y) 的第一个 band 的偏移量。 |
int |
getOffset(int x,
int y,
int b)
获取像素 (x,y) 的 band b 的偏移量。 |
int[] |
getPixel(int x,
int y,
int[] iArray,
DataBuffer data)
返回对应 int 数组中指定像素的所有样本,每个数组元素对应一个样本。 |
int[] |
getPixels(int x,
int y,
int w,
int h,
int[] iArray,
DataBuffer data)
返回对应 int 数组中像素指定矩形区域的所有样本(每个数组元素对应一个样本)。 |
int |
getPixelStride()
返回此 ComponentSampleModel 的像素间距。 |
int |
getSample(int x,
int y,
int b,
DataBuffer data)
以 int 形式返回指定 band 中对应于 (x,y) 处像素的样本。 |
double |
getSampleDouble(int x,
int y,
int b,
DataBuffer data)
以 double 形式返回指定 band 中对应于 (x,y) 处像素的样本。 |
float |
getSampleFloat(int x,
int y,
int b,
DataBuffer data)
以 float 形式返回指定 band 中对应于 (x,y) 处像素的样本。 |
int[] |
getSamples(int x,
int y,
int w,
int h,
int b,
int[] iArray,
DataBuffer data)
返回指定 band 中对应于 int 数组中指定像素矩形的样本,每个数据数组元素一个样本。 |
int[] |
getSampleSize()
返回所有 band 每个样本的位数。 |
int |
getSampleSize(int band)
返回指定 band 每个样本的位数。 |
int |
getScanlineStride()
返回此 ComponentSampleModel 的扫描行间距。 |
int |
hashCode()
返回该对象的哈希码值。 |
void |
setDataElements(int x,
int y,
Object obj,
DataBuffer data)
根据 TransferType 类型基本数组设置指定 DataBuffer 中单个像素的数据。 |
void |
setPixel(int x,
int y,
int[] iArray,
DataBuffer data)
使用输入样本的 int 数组设置 DataBuffer 中的像素。 |
void |
setPixels(int x,
int y,
int w,
int h,
int[] iArray,
DataBuffer data)
根据 int 数组(每个数组元素包含一个样本)设置对应于像素矩形区域的所有样本。 |
void |
setSample(int x,
int y,
int b,
double s,
DataBuffer data)
使用输入的 double 值,在指定 band 中设置对应于 DataBuffer 中 (x,y) 处像素的样本。 |
void |
setSample(int x,
int y,
int b,
float s,
DataBuffer data)
使用输入的 float 值,在指定 band 中设置对应于 DataBuffer 中 (x,y) 处像素的样本。 |
void |
setSample(int x,
int y,
int b,
int s,
DataBuffer data)
使用输入的 int 值,在指定 band 中设置对应于 DataBuffer 中 (x,y) 处像素的样本。 |
void |
setSamples(int x,
int y,
int w,
int h,
int b,
int[] iArray,
DataBuffer data)
根据 int 数组(每个数据数组元素包含一个样本),在指定 band 中设置对应于指定像素矩形的样本。 |
| 从类 java.awt.image.SampleModel 继承的方法 |
|---|
getDataElements, getDataType, getHeight, getNumBands, getPixel, getPixel, getPixels, getPixels, getSamples, getSamples, getTransferType, getWidth, setDataElements, setPixel, setPixel, setPixels, setPixels, setSamples, setSamples |
| 从类 java.lang.Object 继承的方法 |
|---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
| 字段详细信息 |
|---|
protected int[] bandOffsets
protected int[] bankIndices
protected int numBands
ComponentSampleModel 中的 band 数量。
protected int numBanks
ComponentSampleModel 中的存储单元数量。
protected int scanlineStride
protected int pixelStride
| 构造方法详细信息 |
|---|
public ComponentSampleModel(int dataType,
int w,
int h,
int pixelStride,
int scanlineStride,
int[] bandOffsets)
dataType - 存储样本的数据类型w - 描述的图像数据区域的宽度(以像素为单位)h - 描述的图像数据区域的高度(以像素为单位)pixelStride - 描述的图像数据区域的像素间距scanlineStride - 描述的图像数据区域的行间距bandOffsets - 所有 band 的偏移量
IllegalArgumentException - 如果 w 或 h 不大于 0
IllegalArgumentException - 如果 pixelStride 小于 0
IllegalArgumentException - 如果 scanlineStride 小于 0
IllegalArgumentException - 如果 numBands 小于 1
IllegalArgumentException - 如果 w 和 h 的乘积大于 Integer.MAX_VALUE
IllegalArgumentException - 如果 dataType 不是受支持的数据类型之一
public ComponentSampleModel(int dataType,
int w,
int h,
int pixelStride,
int scanlineStride,
int[] bankIndices,
int[] bandOffsets)
dataType - 存储样本的数据类型w - 描述的图像数据区域的宽度(以像素为单位)h - 描述的图像数据区域的高度(以像素为单位)pixelStride - 描述的图像数据区域的像素间距scanlineStride - 描述的图像数据区域的行间距bankIndices - 所有 band 的存储单元索引bandOffsets - 所有 band 的 band 偏移量
IllegalArgumentException - 如果 w 或 h 不大于 0
IllegalArgumentException - 如果 pixelStride 小于 0
IllegalArgumentException - 如果 scanlineStride 小于 0
IllegalArgumentException - 如果 bankIndices 的长度不等于 bankOffsets 的长度
IllegalArgumentException - 如果 bandIndices 的 band 索引中任何一项小于 0
IllegalArgumentException - 如果 dataType 不是受支持的数据类型之一| 方法详细信息 |
|---|
public SampleModel createCompatibleSampleModel(int w,
int h)
ComponentSampleModel。新的 SampleModel 将有与此 SampleModel 相同的 band 数量、存储数据类型、交错方案和像素间距。
SampleModel 中的 createCompatibleSampleModelw - 得到的 SampleModel 的宽度h - 得到的 SampleModel 的高度
ComponentSampleModel
IllegalArgumentException - 如果 w 或 h 不大于 0public SampleModel createSubsetSampleModel(int[] bands)
SampleModel 中的 createSubsetSampleModelbands - 此 ComponentSampleModel 的 band 子集
ComponentSampleModel band 子集的 ComponentSampleModel。public DataBuffer createDataBuffer()
ComponentSampleModel 的 DataBuffer。DataBuffer 对象的数据类型、存储单元的数量和大小与此 ComponentSampleModel 一致。
SampleModel 中的 createDataBufferComponentSampleModel 一致的 DataBuffer。
public int getOffset(int x,
int y)
ComponentSampleModel csm 的 DataBuffer data 中检索,如下所示:
data.getElem(csm.getOffset(x, y));
x - 像素的 X 坐标y - 像素的 Y 坐标
public int getOffset(int x,
int y,
int b)
b 的样本可以从具有 ComponentSampleModel csm 的 DataBuffer data 中检索,如下所示:
data.getElem(csm.getOffset(x, y, b));
x - 指定像素的 X 坐标y - 指定像素的 Y 坐标b - 指定的 band
public final int[] getSampleSize()
SampleModel 中的 getSampleSizepublic final int getSampleSize(int band)
SampleModel 中的 getSampleSizeband - 指定的 band
public final int[] getBankIndices()
public final int[] getBandOffsets()
public final int getScanlineStride()
ComponentSampleModel 的扫描行间距。public final int getPixelStride()
ComponentSampleModel 的像素间距。public final int getNumDataElements()
getDataElements(int, int, Object, DataBuffer) 和 setDataElements(int, int, Object, DataBuffer) 方法传输像素所需的数据元素的数量。对于 ComponentSampleModel,这与 band 的数量相同。
SampleModel 中的 getNumDataElementsgetDataElements 和 setDataElements 方法传输像素所需的数据元素的数量。SampleModel.getNumDataElements(),
SampleModel.getNumBands()
public Object getDataElements(int x,
int y,
Object obj,
DataBuffer data)
TransferType 类型基本数组形式返回单个像素的数据。对于 ComponentSampleModel,返回的数据与 data 类型相同,且每个数组元素返回一个样本。通常,obj 应该作为 null 传入,以便 Object 能自动创建并成为正确的基本数据类型。
以下代码说明了如何将像素的数据从 DataBuffer db1(其存储布局由 ComponentSampleModel csm1 描述)传输到 DataBuffer db2(其存储布局由 ComponentSampleModel csm2 描述)。该传输通常比使用 getPixel 和 setPixel 更有效。
ComponentSampleModel csm1, csm2;
DataBufferInt db1, db2;
csm2.setDataElements(x, y,
csm1.getDataElements(x, y, null, db1), db2);
如果 SampleModel 对象具有相同数量的 band,相应 band 具有相同数量的每样本位数,并且 TransferType 相同,则使用 getDataElements 和 setDataElements 在两个 DataBuffer/SampleModel 对之间传输是合法的。
如果 obj 不为 null,则它应该是 TransferType 类型的基本数组。否则,将抛出 ClassCastException。如果坐标不在边界内部,或者 obj 不为 null 且不足以保存像素数据,则抛出 ArrayIndexOutOfBoundsException。
SampleModel 中的 getDataElementsx - 像素位置的 X 坐标y - 像素位置的 Y 坐标obj - 如果为非 null,则是一个要在其中返回像素数据的基本数组data - 包含图像数据的 DataBuffer
NullPointerException - 如果数据为 null。
ArrayIndexOutOfBoundsException - 如果坐标不在边界内部,或者 obj 太小而不能保存输出。setDataElements(int, int, Object, DataBuffer)
public int[] getPixel(int x,
int y,
int[] iArray,
DataBuffer data)
ArrayIndexOutOfBoundsException。
SampleModel 中的 getPixelx - 像素位置的 X 坐标y - 像素位置的 Y 坐标iArray - 如果为非 null,则返回此数组中的样本data - 包含图像数据的 DataBuffer
NullPointerException - 如果数据为 null。
ArrayIndexOutOfBoundsException - 如果坐标不在边界内部,或者 iArray 太小而不能保存输出。setPixel(int, int, int[], DataBuffer)
public int[] getPixels(int x,
int y,
int w,
int h,
int[] iArray,
DataBuffer data)
ArrayIndexOutOfBoundsException。
SampleModel 中的 getPixelsx - 左上角像素位置的 X 坐标y - 左上角像素位置的 Y 坐标w - 像素矩形区域的宽度h - 像素矩形区域的高度iArray - 如果为非 null,则返回此数组中的样本data - 包含图像数据的 DataBuffer
setPixels(int, int, int, int, int[], DataBuffer)
public int getSample(int x,
int y,
int b,
DataBuffer data)
ArrayIndexOutOfBoundsException。
SampleModel 中的 getSamplex - 像素位置的 X 坐标y - 像素位置的 Y 坐标b - 要返回的 banddata - 包含图像数据的 DataBuffer
setSample(int, int, int, int, DataBuffer)
public float getSampleFloat(int x,
int y,
int b,
DataBuffer data)
ArrayIndexOutOfBoundsException。
SampleModel 中的 getSampleFloatx - 像素位置的 X 坐标y - 像素位置的 Y 坐标b - 要返回的 banddata - 包含图像数据的 DataBuffer
public double getSampleDouble(int x,
int y,
int b,
DataBuffer data)
ArrayIndexOutOfBoundsException。
SampleModel 中的 getSampleDoublex - 像素位置的 X 坐标y - 像素位置的 Y 坐标b - 要返回的 banddata - 包含图像数据的 DataBuffer
public int[] getSamples(int x,
int y,
int w,
int h,
int b,
int[] iArray,
DataBuffer data)
ArrayIndexOutOfBoundsException。
SampleModel 中的 getSamplesx - 左上角像素位置的 X 坐标y - 左上角像素位置的 Y 坐标w - 像素矩形区域的宽度h - 像素矩形区域的高度b - 要返回的 bandiArray - 如果为非 null,则返回此数组中的样本data - 包含图像数据的 DataBuffer
setSamples(int, int, int, int, int, int[], DataBuffer)
public void setDataElements(int x,
int y,
Object obj,
DataBuffer data)
TransferType 类型基本数组设置指定 DataBuffer 中单个像素的数据。对于 ComponentSampleModel,设置的数据与 data 类型相同,且每个数组元素传输一个样本。
以下代码说明了如何将像素的数据从 DataBuffer db1(其存储布局由 ComponentSampleModel csm1 描述)传输到 DataBuffer db2(其存储布局由 ComponentSampleModel csm2 描述)。该传输通常比使用 getPixel 和 setPixel 更有效。
ComponentSampleModel csm1, csm2;
DataBufferInt db1, db2;
csm2.setDataElements(x, y, csm1.getDataElements(x, y, null, db1),
db2);
如果 SampleModel 对象具有相同数量的 band,相应 band 具有相同数量的每样本位数,并且 TransferType 相同,则使用 getDataElements 和 setDataElements 在两个 DataBuffer/SampleModel 对之间传输是合法的。
如果 obj 不是 TransferType 类型基本数组,则返回 ClassCastException。如果坐标不在边界内部,或者 obj 不足以保存像素数据,则抛出 ArrayIndexOutOfBoundsException。
SampleModel 中的 setDataElementsx - 像素位置的 X 坐标y - 像素位置的 Y 坐标obj - 包含像素数据的基本数组data - 包含图像数据的 DataBuffergetDataElements(int, int, Object, DataBuffer)
public void setPixel(int x,
int y,
int[] iArray,
DataBuffer data)
DataBuffer 中的像素。如果坐标不在边界内部,则抛出 ArrayIndexOutOfBoundsException。
SampleModel 中的 setPixelx - 像素位置的 X 坐标y - 像素位置的 Y 坐标iArray - int 数组形式的输入样本data - 包含图像数据的 DataBuffergetPixel(int, int, int[], DataBuffer)
public void setPixels(int x,
int y,
int w,
int h,
int[] iArray,
DataBuffer data)
ArrayIndexOutOfBoundsException。
SampleModel 中的 setPixelsx - 像素位置左上角的 X 坐标y - 像素位置左上角的 Y 坐标w - 像素矩形区域的宽度h - 像素矩形区域的高度iArray - int 数组形式的输入样本data - 包含图像数据的 DataBuffergetPixels(int, int, int, int, int[], DataBuffer)
public void setSample(int x,
int y,
int b,
int s,
DataBuffer data)
DataBuffer 中 (x,y) 处像素的样本。如果坐标不在边界内部,则抛出 ArrayIndexOutOfBoundsException。
SampleModel 中的 setSamplex - 像素位置的 X 坐标y - 像素位置的 Y 坐标b - 要设置的 bands - int 类型的输入样本data - 包含图像数据的 DataBuffergetSample(int, int, int, DataBuffer)
public void setSample(int x,
int y,
int b,
float s,
DataBuffer data)
DataBuffer 中 (x,y) 处像素的样本。如果坐标不在边界内部,则抛出 ArrayIndexOutOfBoundsException。
SampleModel 中的 setSamplex - 像素位置的 X 坐标y - 像素位置的 Y 坐标b - 要设置的 bands - float 类型的输入样本data - 包含图像数据的 DataBuffergetSample(int, int, int, DataBuffer)
public void setSample(int x,
int y,
int b,
double s,
DataBuffer data)
DataBuffer 中 (x,y) 处像素的样本。如果坐标不在边界内部,则抛出 ArrayIndexOutOfBoundsException。
SampleModel 中的 setSamplex - 像素位置的 X 坐标y - 像素位置的 Y 坐标b - 要设置的 bands - double 类型的输入样本data - 包含图像数据的 DataBuffergetSample(int, int, int, DataBuffer)
public void setSamples(int x,
int y,
int w,
int h,
int b,
int[] iArray,
DataBuffer data)
ArrayIndexOutOfBoundsException。
SampleModel 中的 setSamplesx - 像素位置左上角的 X 坐标y - 像素位置左上角的 Y 坐标w - 像素矩形区域的宽度h - 像素矩形区域的高度b - 要设置的 bandiArray - int 数组形式的输入样本data - 包含图像数据的 DataBuffergetSamples(int, int, int, int, int, int[], DataBuffer)public boolean equals(Object o)
Object 复制的描述
equals 方法在非空对象引用上实现相等关系:
x,x.equals(x) 都应返回 true。
x 和 y,当且仅当 y.equals(x) 返回 true 时,x.equals(y) 才应返回 true。
x、y 和 z,如果 x.equals(y) 返回 true,并且 y.equals(z) 返回 true,那么 x.equals(z) 应返回 true。
x 和 y,多次调用 x.equals(y) 始终返回 true 或始终返回 false,前提是对象上 equals 比较中所用的信息没有被修改。
x,x.equals(null) 都应返回 false。
Object 类的 equals 方法实现对象上差别可能性最大的相等关系;即,对于任何非空引用值 x 和 y,当且仅当 x 和 y 引用同一个对象时,此方法才返回 true(x == y 具有值 true)。
注意:当此方法被重写时,通常有必要重写 hashCode 方法,以维护 hashCode 方法的常规协定,该协定声明相等对象必须具有相等的哈希码。
Object 中的 equalso - 要与之比较的引用对象。
true;否则返回 false。Object.hashCode(),
Hashtablepublic int hashCode()
Object 复制的描述java.util.Hashtable 提供的哈希表)的性能。
hashCode 的常规协定是:
hashCode 方法都必须生成相同的整数结果。
Object.equals(java.lang.Object) 方法,两个对象不相等,那么对这两个对象中的任一对象上调用 hashCode 方法不 要求一定生成不同的整数结果。但是,程序员应该意识到,为不相等的对象生成不同整数结果可以提高哈希表的性能。
实际上,由 Object 类定义的 hashCode 方法确实会针对不同的对象返回不同的整数。(这一般是通过将该对象的内部地址转换成一个整数来实现的,但是 JavaTM 编程语言不需要这种实现技巧。)
Object 中的 hashCodeObject.equals(java.lang.Object),
Hashtable
|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。