java.lang.Objectjava.awt.image.Raster
java.awt.image.WritableRaster
public class WritableRaster
此类扩展了 Raster 以提供像素写入功能。有关 Raster 如何存储像素的描述,请参阅 Raster 的类注释。
此类的构造方法为 protected。要实例化 WritableRaster,需使用 Raster 类中的一个 createWritableRaster 工厂方法。
| 字段摘要 |
|---|
| 从类 java.awt.image.Raster 继承的字段 |
|---|
dataBuffer, height, minX, minY, numBands, numDataElements, parent, sampleModel, sampleModelTranslateX, sampleModelTranslateY, width |
| 构造方法摘要 | |
|---|---|
protected |
WritableRaster(SampleModel sampleModel, DataBuffer dataBuffer, Point origin) 构造具有给定 SampleModel 和 DataBuffer 的 WritableRaster。 |
protected |
WritableRaster(SampleModel sampleModel, DataBuffer dataBuffer, Rectangle aRegion, Point sampleModelTranslate, WritableRaster parent) 构造具有给定 SampleModel、DataBuffer 和父亲的 WritableRaster。 |
protected |
WritableRaster(SampleModel sampleModel, Point origin) 构造具有给定 SampleModel 的 WritableRaster。 |
| 方法摘要 | |
|---|---|
WritableRaster |
createWritableChild(int parentX, int parentY, int w, int h, int childMinX, int childMinY, int[] bandList) 返回新的 WritableRaster,它共享此 WritableRaster 的全部或部分 DataBuffer。 |
WritableRaster |
createWritableTranslatedChild(int childMinX, int childMinY) 在不同的位置上创建一个与此 WritableRaster 具有相同大小、SampleModel 和 DataBuffer 的 WritableRaster。 |
WritableRaster |
getWritableParent() 返回此 WritableRaster 的父 WritableRaster(如果有),否则返回 null。 |
void |
setDataElements(int x, int y, int w, int h, Object inData) 为类型 TransferType 基本数组中的像素矩形设置数据。 |
void |
setDataElements(int x, int y, Object inData) 为类型 TransferType 基本数组中的单个像素设置数据。 |
void |
setDataElements(int x, int y, Raster inRaster) 为输入 Raster 中的像素矩形设置数据。 |
void |
setPixel(int x, int y, double[] dArray) 使用输入样本的 double 型数组设置 DataBuffer 中的像素。 |
void |
setPixel(int x, int y, float[] fArray) 使用输入样本的 float 型数组设置 DataBuffer 中的像素。 |
void |
setPixel(int x, int y, int[] iArray) 使用输入样本的 int 型数组设置 DataBuffer 中的像素。 |
void |
setPixels(int x, int y, int w, int h, double[] dArray) 为每个数组元素包含一个样本的 double 型数组中的像素矩形设置所有样本。 |
void |
setPixels(int x, int y, int w, int h, float[] fArray) 为每个数组元素包含一个样本的 float 型数组中的像素矩形设置所有样本。 |
void |
setPixels(int x, int y, int w, int h, int[] iArray) 为每个数组元素包含一个样本的 int 型数组中的像素矩形设置所有样本。 |
void |
setRect(int dx, int dy, Raster srcRaster) 将像素从 Raster srcRaster 复制到此 WritableRaster。 |
void |
setRect(Raster srcRaster) 将像素从 Raster srcRaster 复制到此 WritableRaster。 |
void |
setSample(int x, int y, int b, double s) 使用 double 型的输入样本,在指定 band 中为位于 DataBuffer 中 (x,y) 位置的像素设置样本。 |
void |
setSample(int x, int y, int b, float s) 使用 float 型的输入样本,在指定 band 中为位于 DataBuffer 中 (x,y) 位置的像素设置样本。 |
void |
setSample(int x, int y, int b, int s) 使用 int 型的输入样本,在指定 band 中为位于 DataBuffer 中 (x,y) 位置的像素设置样本。 |
void |
setSamples(int x, int y, int w, int h, int b, double[] dArray) 为每个数组元素包含一个样本的 double 型数组中指定的像素矩形在指定 band 中设置样本。 |
void |
setSamples(int x, int y, int w, int h, int b, float[] fArray) 为每个数组元素包含一个样本的 float 型数组中指定的像素矩形在指定 band 中设置样本。 |
void |
setSamples(int x, int y, int w, int h, int b, int[] iArray) 为每个数组元素包含一个样本的 int 型数组中指定的像素矩形在指定 band 中设置样本。 |
| 从类 java.lang.Object 继承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 构造方法详细信息 |
|---|
protected WritableRaster(SampleModel sampleModel, Point origin)
sampleModel - 指定布局的 SampleModel。
origin - 指定原点的 Point。
RasterFormatException - 如果
origin.x + sampleModel.getWidth() 或者
origin.y + sampleModel.getHeight() 的计算结果整数溢出
protected WritableRaster(SampleModel sampleModel, DataBuffer dataBuffer, Point origin)
sampleModel - 指定布局的 SampleModel。
dataBuffer - 包含图像数据的 DataBuffer。
origin - 指定原点的 Point。
RasterFormatException - 如果
origin.x + sampleModel.getWidth() 或
origin.y + sampleModel.getHeight() 的计算结果整数溢出
protected WritableRaster(SampleModel sampleModel, DataBuffer dataBuffer, Rectangle aRegion, Point sampleModelTranslate, WritableRaster parent)
sampleModel - 指定布局的 SampleModel。
dataBuffer - 包含图像数据的 DataBuffer。
aRegion - 指定图像区域的 Rectangle。
sampleModelTranslate - 指定从 SampleModel 向 Raster 进行坐标转换的 Point。
parent - 此 raster 的父亲(如果有)。
RasterFormatException - 如果
aRegion 的宽度和高度小于等于 0,或者
aRegion.x + aRegion.width 或
aRegion.y + aRegion.height 的计算结果整数溢出
| 方法详细信息 |
|---|
public WritableRaster getWritableParent()
WritableRaster 的父亲,或
null。
public WritableRaster createWritableTranslatedChild(int childMinX, int childMinY)
childMinX - 新 Raster 左上角的 X 坐标。
childMinY - 新 Raster 左上角的 Y 坐标。
WritableRaster 相同的
WritableRaster。
RasterFormatException - 如果
childMinX + this.getWidth() 或
childMinY + this.getHeight() 的计算结果整数溢出
public WritableRaster createWritableChild(int parentX, int parentY, int w, int h, int childMinX, int childMinY, int[] bandList)
parentX、parentY、width 和 height 参数在此 WritableRaster 坐标空间中形成一个 Rectangle,指示要共享的像素区域。如果此 Rectangle 没有包含在当前 WritableRaster 的边界内部,则会抛出错误。
新 WritableRaster 可以另外转换到与当前 WritableRaster 不同的平面坐标系中。childMinX 和 childMinY 参数给定返回的 WritableRaster 左上角像素的新 (x, y) 坐标;新 WritableRaster 中的坐标 (childMinX, childMinY) 将映射到当前 WritableRaster 中相同像素的坐标 (parentX, parentY)。
新 WritableRaster 可以定义为只包含当前 WritableRaster band 的一个子集,该子集可能通过 bandList 参数进行了重新排序。如果 bandList 为 null,则它将以其当前顺序包含当前 WritableRaster 的所有 band。
要创建新的 WritableRaster,使其包含当前 WritableRaster 的子区域,但共享其坐标系和 band,此方法在调用时应该令 childMinX 等于 parentX,childMinY 等于 parentY 且 bandList 为 null。
parentX - 此 WritableRaster 坐标中左上角的 X 坐标。
parentY - 此 WritableRaster 坐标中左上角的 Y 坐标。
w - 从 (parentX, parentY) 开始的区域宽度。
w - 从 (parentX, parentY) 开始的区域高度。
childMinX - 返回的 WritableRaster 左上角的 X 坐标。
childMinY - 返回的 WritableRaster 左上角的 Y 坐标。
bandList - band 的索引数组,取 null 则使用所有 band。
WritableRaster,它共享此
WritableRaster 全部或部分
DataBuffer。
RasterFormatException - 如果子区域位于光栅边界的外部。
RasterFormatException - 如果
w 或
h 小于等于 0,或者
parentX + w、
parentY + h、
childMinX + w 或
childMinY + h 中任何一个的计算结果整数溢出
public void setDataElements(int x,
int y,
Object inData)
x - 像素位置的 X 坐标。
y - 像素位置的 Y 坐标。
inData - 引用类型数组的对象,该类型由 getTransferType() 定义,并且其长度 getNumDataElements() 包含到 x,y 位置的像素数据。
ArrayIndexOutOfBoundsException - 如果坐标不在边界内部,或者 inData 太小不能容纳输入。
SampleModel.setDataElements(int, int, Object, DataBuffer)
public void setDataElements(int x,
int y,
Raster inRaster)
x - 像素位置的 X 坐标。
y - 像素位置的 Y 坐标。
inRaster - 包含 x,y 位置数据的 Raster。
NullPointerException - 如果 inRaster 为 null。
ArrayIndexOutOfBoundsException - 如果坐标不在边界内部。
public void setDataElements(int x,
int y,
int w,
int h,
Object inData)
x - 左上角像素位置的 X 坐标。
y - 左上角像素位置的 Y 坐标。
w - 像素矩形的宽度。
h - 像素矩形的高度。
inData - 引用类型数组的对象,该类型是由 getTransferType() 定义的,并且它的长度 w*h*getNumDataElements() 包含 x,y 和 x+w-1, y+h-1 位置之间的像素数据。
NullPointerException - 如果 inData 为 null。
ArrayIndexOutOfBoundsException - 如果坐标不在边界内部,或者 inData 太小不能容纳输入。
SampleModel.setDataElements(int, int, int, int, Object, DataBuffer)
public void setRect(Raster srcRaster)
如果源 Raster 和目标 Raster 的所有样本都是整型,且大小小于等于 32 位,则调用此方法等价于对源 Raster 和目标 Raster 中所有有效的 x,y 地址执行以下代码。
Raster srcRaster;
WritableRaster dstRaster;
for (int b = 0; b < srcRaster.getNumBands(); b++) {
dstRaster.setSample(x, y, b, srcRaster.getSample(x, y, b));
}
因此,当将整型的源复制到整型的目标时,如果对于特定的 band 源样本大小大于目标样本大小,则源样本的高位将被截断。如果特定 band 的源样本大小小于目标样本大小,则根据 srcRaster 的 SampleModel 是将样本作为有符号的量还是无符号的量,对目标样本的高位进行零扩展或符号扩展。
当从一个 float 型或 double 型的源复制到整型的目标时,每个源样本强制转换为目标类型。当从整形的源复制到 float 型或 double 型的目标时,源首先使用上面的整型转换规则转换为 32-位的 int(如果需要的话),然后此 int 强制转换为 float 型或 double 型。
srcRaster - 从其复制像素的 Raster。
NullPointerException - 如果 srcRaster 为 null。
public void setRect(int dx,
int dy,
Raster srcRaster)
setRect(Raster)。
dx - 从 src 空间复制到 dst 空间的 X 转换因子。
dy - 从 src 空间复制到 dst 空间的 Y 转换因子。
srcRaster - 从其复制像素的 Raster。
NullPointerException - 如果 srcRaster 为 null。
public void setPixel(int x,
int y,
int[] iArray)
x - 像素位置的 X 坐标。
y - 像素位置的 Y 坐标。
iArray - 以 int 型数组表示的输入样本。
NullPointerException - 如果 iArray 为 null。
ArrayIndexOutOfBoundsException - 如果坐标不在边界内部,或者 iArray 太小不能容纳输入。
public void setPixel(int x,
int y,
float[] fArray)
x - 像素位置的 X 坐标。
y - 像素位置的 Y 坐标。
fArray - 以 float 型数组表示的输入样本。
NullPointerException - 如果 fArray 为 null。
ArrayIndexOutOfBoundsException - 如果坐标不在边界内部,或者 fArray 太小不能容纳输入。
public void setPixel(int x,
int y,
double[] dArray)
x - 像素位置的 X 坐标。
y - 像素位置的 Y 坐标。
dArray - 以 double 型数组表示的输入样本。
NullPointerException - 如果 dArray 为 null。
ArrayIndexOutOfBoundsException - 如果坐标不在边界内部,或者 dArray 太小不能容纳输入。
public void setPixels(int x,
int y,
int w,
int h,
int[] iArray)
x - 左上角像素位置的 X 坐标。
y - 左上角像素位置的 Y 坐标。
w - 像素矩形的宽度。
h - 像素矩形的高度。
iArray - 输入的 int 像素数组。
NullPointerException - 如果 iArray 为 null。
ArrayIndexOutOfBoundsException - 如果坐标不在边界内部,或者 iArray 太小不能容纳输入。
public void setPixels(int x,
int y,
int w,
int h,
float[] fArray)
x - 左上角像素位置的 X 坐标。
y - 左上角像素位置的 Y 坐标。
w - 像素矩形的宽度。
h - 像素矩形的高度。
fArray - 输入的 float 型像素数组。
NullPointerException - 如果 fArray 为 null。
ArrayIndexOutOfBoundsException - 如果坐标不在边界内部,或者 fArray 太小不能容纳输入。
public void setPixels(int x,
int y,
int w,
int h,
double[] dArray)
x - 左上角像素位置的 X 坐标。
y - 左上角像素位置的 Y 坐标。
w - 像素矩形的宽度。
h - 像素矩形的高度。
dArray - 输入的 double 型数组。
NullPointerException - 如果 dArray 为 null。
ArrayIndexOutOfBoundsException - 如果坐标不在边界内部,或者 dArray 太小不能容纳输入。
public void setSample(int x,
int y,
int b,
int s)
x - 像素位置的 X 坐标。
y - 像素位置的 Y 坐标。
b - 要设置的 band。
s - 输入样本。
ArrayIndexOutOfBoundsException - 如果坐标或 band 索引不在边界内部。
public void setSample(int x,
int y,
int b,
float s)
x - 像素位置的 X 坐标。
y - 像素位置的 Y 坐标。
b - 要设置的 band。
s - 以 float 的形式输入的样本。
ArrayIndexOutOfBoundsException - 如果坐标或 band 索引不在边界内部。
public void setSample(int x,
int y,
int b,
double s)
x - 像素位置的 X 坐标。
y - 像素位置的 Y 坐标。
b - 要设置的 band。
s - 以 double 形式输入的样本。
ArrayIndexOutOfBoundsException - 如果坐标或 band 索引不在边界内部。
public void setSamples(int x,
int y,
int w,
int h,
int b,
int[] iArray)
x - 左上角像素位置的 X 坐标。
y - 左上角像素位置的 Y 坐标。
w - 像素矩形的宽度。
h - 像素矩形的高度。
b - 要设置的 band。
iArray - 输入的 int 型样本数组。
NullPointerException - 如果 iArray 为 null。
ArrayIndexOutOfBoundsException - 如果坐标或 band 索引不在边界内部,或者 iArray 太小不能容纳输入。
public void setSamples(int x,
int y,
int w,
int h,
int b,
float[] fArray)
x - 左上角像素位置的 X 坐标。
y - 左上角像素位置的 Y 坐标。
w - 像素矩形的宽度。
h - 像素矩形的高度。
b - 要设置的 band。
fArray - 输入的 float 型样本数组。
NullPointerException - 如果 fArray 为 null。
ArrayIndexOutOfBoundsException - 如果坐标或 band 索引不在边界内部,或者 fArray 太小不能容纳输入。
public void setSamples(int x,
int y,
int w,
int h,
int b,
double[] dArray)
x - 左上角像素位置的 X 坐标。
y - 左上角像素位置的 Y 坐标。
w - 像素矩形的宽度。
h - 像素矩形的高度。
b - 要设置的 band。
dArray - 输入的 double 型样本数组。
NullPointerException - 如果 dArray 为 null。
ArrayIndexOutOfBoundsException - 如果坐标或 band 索引不在边界内,或者 dArray 太小不能容纳输入。