|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectjava.awt.image.MemoryImageSource
public class MemoryImageSource
此类是 ImageProducer 接口的一个实现,该接口使用一个数组为 Image 生成像素值。下面的示例计算了一幅 100x100 的图像,表示沿 X 轴从黑色渐变到蓝色,沿 Y 轴从黑色渐变到红色:
int w = 100;
int h = 100;
int pix[] = new int[w * h];
int index = 0;
for (int y = 0; y < h; y++) {
int red = (y * 255) / (h - 1);
for (int x = 0; x < w; x++) {
int blue = (x * 255) / (w - 1);
pix[index++] = (255 << 24) | (red << 16) | blue;
}
}
Image img = createImage(new MemoryImageSource(w, h, pix, 0, w));
MemoryImageSource 还能够管理随时间的推移而变化的内存图像,以实现动画或自定义呈现。下面的示例显示了如何设置动画源并通知数据的改变(改编自 Garth Dickie 的 MemoryAnimationSourceDemo):
int pixels[];
MemoryImageSource source;
public void init() {
int width = 50;
int height = 50;
int size = width * height;
pixels = new int[size];
int value = getBackground().getRGB();
for (int i = 0; i < size; i++) {
pixels[i] = value;
}
source = new MemoryImageSource(width, height, pixels, 0, width);
source.setAnimated(true);
image = createImage(source);
}
public void run() {
Thread me = Thread.currentThread( );
me.setPriority(Thread.MIN_PRIORITY);
while (true) {
try {
thread.sleep(10);
} catch( InterruptedException e ) {
return;
}
// Modify the values in the pixels array at (x, y, w, h)
// Send the new data to the interested ImageConsumers
source.newPixels(x, y, w, h);
}
}
ImageProducer| 构造方法摘要 | |
|---|---|
MemoryImageSource(int w,
int h,
ColorModel cm,
byte[] pix,
int off,
int scan)
构造一个使用 byte 数组为 Image 对象生成数据的 ImageProducer 对象。 |
|
MemoryImageSource(int w,
int h,
ColorModel cm,
byte[] pix,
int off,
int scan,
Hashtable<?,?> props)
构造一个使用 byte 数组为 Image 对象生成数据的 ImageProducer 对象。 |
|
MemoryImageSource(int w,
int h,
ColorModel cm,
int[] pix,
int off,
int scan)
构造一个使用整数数组为 Image 对象生成数据的 ImageProducer 对象。 |
|
MemoryImageSource(int w,
int h,
ColorModel cm,
int[] pix,
int off,
int scan,
Hashtable<?,?> props)
构造一个使用整数数组为 Image 对象生成数据的 ImageProducer 对象。 |
|
MemoryImageSource(int w,
int h,
int[] pix,
int off,
int scan)
构造一个使用默认 RGB ColorModel 中的整数数组为 Image 对象生成数据的 ImageProducer 对象。 |
|
MemoryImageSource(int w,
int h,
int[] pix,
int off,
int scan,
Hashtable<?,?> props)
构造一个使用默认 RGB ColorModel 中的整数数组为 Image 对象生成数据的 ImageProducer 对象。 |
|
| 方法摘要 | |
|---|---|
void |
addConsumer(ImageConsumer ic)
将 ImageConsumer 添加到对此图像数据感兴趣的使用者列表。 |
boolean |
isConsumer(ImageConsumer ic)
确定某个 ImageConsumer 目前是否处于对此图像数据感兴趣的使用者列表中。 |
void |
newPixels()
将全部的新像素缓冲区发送到所有目前对此图像数据感兴趣的 ImageConsumer,并通知这些 ImageConsumer 一个动画帧已完成。 |
void |
newPixels(byte[] newpix,
ColorModel newmodel,
int offset,
int scansize)
改用一个新的 byte 数组以保存此图像的像素。 |
void |
newPixels(int[] newpix,
ColorModel newmodel,
int offset,
int scansize)
改用一个新的 int 数组以保存此图像的像素。 |
void |
newPixels(int x,
int y,
int w,
int h)
将像素缓冲区的矩形区域发送到所有目前对此图像数据感兴趣的 ImageConsumer,并通知这些 ImageConsumer 一个动画帧已完成。 |
void |
newPixels(int x,
int y,
int w,
int h,
boolean framenotify)
将像素缓冲区的矩形区域发送到所有目前对此图像数据感兴趣的 ImageConsumer。 |
void |
removeConsumer(ImageConsumer ic)
从对此图像数据感兴趣的使用者列表中移除 ImageConsumer。 |
void |
requestTopDownLeftRightResend(ImageConsumer ic)
请求给定的 ImageConsumer 再次按从上到下、从左到右的顺序传递图像数据。 |
void |
setAnimated(boolean animated)
根据 animated 参数将此内存图像更改为多帧动画或单帧静态图像。 |
void |
setFullBufferUpdates(boolean fullbuffers)
指定在像素缓冲区发生变化时,是否总是通过发送像素的完整缓冲区来更新此动画内存图像。 |
void |
startProduction(ImageConsumer ic)
将 ImageConsumer 添加到对此图像数据感兴趣的使用者列表中,并立即开始通过 ImageConsumer 接口传递图像数据。 |
| 从类 java.lang.Object 继承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 构造方法详细信息 |
|---|
public MemoryImageSource(int w,
int h,
ColorModel cm,
byte[] pix,
int off,
int scan)
w - 像素矩形的宽度h - 像素矩形的高度cm - 指定的 ColorModelpix - 一个像素数组off - 数组中存储首个像素的偏移量scan - 数组中一行像素到下一行像素之间的距离Component.createImage(java.awt.image.ImageProducer)
public MemoryImageSource(int w,
int h,
ColorModel cm,
byte[] pix,
int off,
int scan,
Hashtable<?,?> props)
w - 像素矩形的宽度h - 像素矩形的高度cm - 指定的 ColorModelpix - 一个像素数组off - 数组中存储首个像素的偏移量scan - 数组中一行像素到下一行像素之间的距离props - ImageProducer 用于处理图像的属性列表Component.createImage(java.awt.image.ImageProducer)
public MemoryImageSource(int w,
int h,
ColorModel cm,
int[] pix,
int off,
int scan)
w - 像素矩形的宽度h - 像素矩形的高度cm - 指定的 ColorModelpix - 一个像素数组off - 数组中存储首个像素的偏移量scan - 数组中一行像素到下一行像素之间的距离Component.createImage(java.awt.image.ImageProducer)
public MemoryImageSource(int w,
int h,
ColorModel cm,
int[] pix,
int off,
int scan,
Hashtable<?,?> props)
w - 像素矩形的宽度h - 像素矩形的高度cm - 指定的 ColorModelpix - 一个像素数组off - 数组中存储首个像素的偏移量scan - 数组中一行像素到下一行像素之间的距离props - ImageProducer 用于处理图像的属性列表Component.createImage(java.awt.image.ImageProducer)
public MemoryImageSource(int w,
int h,
int[] pix,
int off,
int scan)
w - 像素矩形的宽度h - 像素矩形的高度pix - 一个像素数组off - 数组中存储首个像素的偏移量scan - 数组中一行像素到下一行像素之间的距离Component.createImage(java.awt.image.ImageProducer),
ColorModel.getRGBdefault()
public MemoryImageSource(int w,
int h,
int[] pix,
int off,
int scan,
Hashtable<?,?> props)
w - 像素矩形的宽度h - 像素矩形的高度pix - 一个像素数组off - 数组中存储首个像素的偏移量scan - 数组中一行像素到下一行像素之间的距离props - ImageProducer 用于处理图像的属性列表Component.createImage(java.awt.image.ImageProducer),
ColorModel.getRGBdefault()| 方法详细信息 |
|---|
public void addConsumer(ImageConsumer ic)
ImageProducer 中的 addConsumeric - 指定的 ImageConsumer
NullPointerException - 如果指定的 ImageConsumer 为 nullImageConsumerpublic boolean isConsumer(ImageConsumer ic)
ImageProducer 中的 isConsumeric - 指定的 ImageConsumer
ImageConsumer 处于列表中,则返回 true;否则返回 false。ImageConsumerpublic void removeConsumer(ImageConsumer ic)
ImageProducer 中的 removeConsumeric - 指定的 ImageConsumerImageConsumerpublic void startProduction(ImageConsumer ic)
ImageProducer 中的 startProductionic - 通过 ImageConsumer 接口的指定 ImageConsumer 图像数据。ImageConsumerpublic void requestTopDownLeftRightResend(ImageConsumer ic)
ImageProducer 中的 requestTopDownLeftRightResendic - 指定的 ImageConsumerImageConsumerpublic void setAnimated(boolean animated)
应该在构造 MemoryImageSource 后和使用它创建图像前立即调用此方法,以确保所有的 ImageConsumer 都将接收正确的多帧数据。如果在设置此标志前将一个 ImageConsumer 添加到此 ImageProducer 中,则该 ImageConsumer 将只能看到在它连接时可用的一个像素数据快照。
animated - 如果该图像是一个多帧动画,则为 truepublic void setFullBufferUpdates(boolean fullbuffers)
应该在构造 MemoryImageSource 后和使用它创建图像前立即调用此方法,以确保所有的 ImageConsumer 都将接收正确的像素传递提示。
fullbuffers - 如果总是应该发送完整的像素缓冲区,则为 truesetAnimated(boolean)public void newPixels()
newPixels(int, int, int, int, boolean),
ImageConsumer,
setAnimated(boolean)
public void newPixels(int x,
int y,
int w,
int h)
x - 要发送的像素矩形左上角的 x 坐标y - 要发送的像素矩形左上角的 y 坐标w - 要发送的像素矩形的宽度h - 要发送的像素矩形的高度newPixels(int, int, int, int, boolean),
ImageConsumer,
setAnimated(boolean),
setFullBufferUpdates(boolean)
public void newPixels(int x,
int y,
int w,
int h,
boolean framenotify)
x - 要发送的像素矩形左上角的 x 坐标y - 要发送的像素矩形左上角的 y 坐标w - 要发送的像素矩形的宽度h - 要发送的像素矩形的高度framenotify - 如果应该向使用者发送 SINGLEFRAMEDONE 通知,则为 trueImageConsumer,
setAnimated(boolean),
setFullBufferUpdates(boolean)
public void newPixels(byte[] newpix,
ColorModel newmodel,
int offset,
int scansize)
newpix - 新的像素数组newmodel - 指定的 ColorModeloffset - 数组中的偏移量scansize - 数组中一行像素到下一行像素之间的距离newPixels(int, int, int, int, boolean),
setAnimated(boolean)
public void newPixels(int[] newpix,
ColorModel newmodel,
int offset,
int scansize)
newpix - 新的像素数组newmodel - 指定的 ColorModeloffset - 数组中的偏移量scansize - 数组中一行像素到下一行像素之间的距离newPixels(int, int, int, int, boolean),
setAnimated(boolean)
|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。