public class MemoryImageSource extends Object implements ImageProducer
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
Constructor and Description |
---|
MemoryImageSource(int w, int h, ColorModel cm, byte[] pix, int off, int scan)
构建了一个imageproducer对象使用一个字节数组为图像对象产生的数据。
|
MemoryImageSource(int w, int h, ColorModel cm, byte[] pix, int off, int scan, Hashtable<?,?> props)
构建了一个imageproducer对象使用一个字节数组为图像对象产生的数据。
|
MemoryImageSource(int w, int h, ColorModel cm, int[] pix, int off, int scan)
构建了一个imageproducer对象使用一个整数数组为图像对象产生的数据。
|
MemoryImageSource(int w, int h, ColorModel cm, int[] pix, int off, int scan, Hashtable<?,?> props)
构建了一个imageproducer对象使用一个整数数组为图像对象产生的数据。
|
MemoryImageSource(int w, int h, int[] pix, int off, int scan)
构建了一个imageproducer对象使用默认的RGB色彩模型的整数数组为图像对象产生的数据。
|
MemoryImageSource(int w, int h, int[] pix, int off, int scan, Hashtable<?,?> props)
构建了一个imageproducer对象使用默认的RGB色彩模型的整数数组为图像对象产生的数据。
|
Modifier and Type | Method and Description |
---|---|
void |
addConsumer(ImageConsumer ic)
增加了一个imageconsumer到该图像的消费者感兴趣的数据列表。
|
boolean |
isConsumer(ImageConsumer ic)
确定imageconsumer是名单上的消费者目前感兴趣的数据,这一形象。
|
void |
newPixels()
发送一个全新的像素缓冲区的任何imageconsumers目前感兴趣的数据对于这个图像,通知他们,一个动画帧是完整的。
|
void |
newPixels(byte[] newpix, ColorModel newmodel, int offset, int scansize)
改变一个新的字节数组来保持这个图像的像素。
|
void |
newPixels(int[] newpix, ColorModel newmodel, int offset, int scansize)
一个新的int数组为图像像素的变化。
|
void |
newPixels(int x, int y, int w, int h)
将像素缓冲区的矩形区域的任何imageconsumers目前感兴趣的数据对于这个图像,通知他们,一个动画帧是完整的。
|
void |
newPixels(int x, int y, int w, int h, boolean framenotify)
将像素缓冲区的矩形区域的任何imageconsumers目前感兴趣的数据对于这个图像。
|
void |
removeConsumer(ImageConsumer ic)
删除从消费者感兴趣的数据列表imageconsumer这个图像。
|
void |
requestTopDownLeftRightResend(ImageConsumer ic)
要求一个给定的图像数据传送imageconsumer自上而下的再一次,左右顺序。
|
void |
setAnimated(boolean animated)
将此存储图像更改为多帧动画或取决于动画参数的单帧静态图像。
|
void |
setFullBufferUpdates(boolean fullbuffers)
指定是否应该总是通过发送像素的完整缓冲区更新这个动画内存图像,每当有一个变化。
|
void |
startProduction(ImageConsumer ic)
增加了一个imageconsumer到该图像的消费者感兴趣的数据列表并立即开始的图像数据通过接口传递imageconsumer。
|
public MemoryImageSource(int w, int h, ColorModel cm, byte[] pix, int off, int scan)
w
-矩形像素宽度
h
-像素的矩形的高度
cm
-指定
ColorModel
pix
-像素阵列
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
-指定
ColorModel
pix
-像素阵列
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
-指定
ColorModel
pix
-像素阵列
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
-指定
ColorModel
pix
-像素阵列
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)
addConsumer
接口
ImageProducer
ic
-指定
ImageConsumer
NullPointerException
-如果指定
ImageConsumer
是空的
ImageConsumer
public boolean isConsumer(ImageConsumer ic)
isConsumer
接口
ImageProducer
ic
-指定
ImageConsumer
true
如果
ImageConsumer
是名单上的;
false
否则。
ImageConsumer
public void removeConsumer(ImageConsumer ic)
removeConsumer
接口
ImageProducer
ic
-指定
ImageConsumer
ImageConsumer
public void startProduction(ImageConsumer ic)
startProduction
接口
ImageProducer
ic
-指定
ImageConsumer
图像数据通过imageconsumer接口。
ImageConsumer
public void requestTopDownLeftRightResend(ImageConsumer ic)
requestTopDownLeftRightResend
接口
ImageProducer
ic
-指定
ImageConsumer
ImageConsumer
public void setAnimated(boolean animated)
这种方法应该在memoryimagesource构造立刻叫之前的图像创建它确保所有imageconsumers会收到正确的多帧数据。如果一个imageconsumer之前设置了该标志,imageconsumer只能看到一个快照的像素数据,可当它连接添加到这个imageproducer。
animated
-
true
如果图像多帧动画
public void setFullBufferUpdates(boolean fullbuffers)
这种方法应该在memoryimagesource构造立刻叫之前的图像创建它确保所有imageconsumers会收到正确的像素传递的暗示。
fullbuffers
-
true
如果完全像素缓冲区应该派
setAnimated(boolean)
public void newPixels()
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
-
true
如果消费者应该发送一
SINGLEFRAMEDONE
通知
ImageConsumer
,
setAnimated(boolean)
,
setFullBufferUpdates(boolean)
public void newPixels(byte[] newpix, ColorModel newmodel, int offset, int scansize)
newpix
-新的像素阵列
newmodel
-指定
ColorModel
offset
-偏移到数组
scansize
-从一行的像素距离数组中的下一
newPixels(int, int, int, int, boolean)
,
setAnimated(boolean)
public void newPixels(int[] newpix, ColorModel newmodel, int offset, int scansize)
newpix
-新的像素阵列
newmodel
-指定
ColorModel
offset
-偏移到数组
scansize
-从一行的像素距离数组中的下一
newPixels(int, int, int, int, boolean)
,
setAnimated(boolean)
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.