- java.lang.Object
-
- java.awt.image.MemoryImageSource
-
- 实现的所有接口
-
ImageProducer
public class MemoryImageSource extends Object implements ImageProducer
此类是ImageProducer接口的实现,它使用数组为Image生成像素值。 下面是一个计算100x100图像的示例,该图像表示沿X轴从黑色到蓝色的淡入淡出和沿Y轴从黑色到红色的淡入淡出:MemoryImageSource还能够管理随时间变化的内存映像,以允许动画或自定义渲染。 下面是一个示例,说明如何设置动画源和数据中的信号变化(改编自Garth Dickie的MemoryAnimationSourceDemo):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));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, int[] pix, int off, int scan)构造一个ImageProducer对象,该对象使用默认RGB ColorModel中的整数数组来为Image对象生成数据。MemoryImageSource(int w, int h, int[] pix, int off, int scan, Hashtable<?,?> props)构造一个ImageProducer对象,该对象使用默认RGB ColorModel中的整数数组来为Image对象生成数据。MemoryImageSource(int w, int h, ColorModel cm, byte[] pix, int off, int scan)构造一个ImageProducer对象,该对象使用字节数组为Image对象生成数据。MemoryImageSource(int w, int h, ColorModel cm, byte[] pix, int off, int scan, Hashtable<?,?> props)构造一个ImageProducer对象,该对象使用字节数组为Image对象生成数据。MemoryImageSource(int w, int h, ColorModel cm, int[] pix, int off, int scan)构造一个ImageProducer对象,该对象使用整数数组为Image对象生成数据。MemoryImageSource(int w, int h, ColorModel cm, int[] pix, int off, int scan, Hashtable<?,?> props)构造一个ImageProducer对象,该对象使用整数数组为Image对象生成数据。
-
方法摘要
所有方法 实例方法 具体的方法 变量和类型 方法 描述 voidaddConsumer(ImageConsumer ic)将ImageConsumer添加到对此图像的数据感兴趣的使用者列表中。booleanisConsumer(ImageConsumer ic)确定ImageConsumer是否位于当前对此图像的数据感兴趣的使用者列表中。voidnewPixels()向当前对此图像的数据感兴趣的任何ImageConsumers发送一个全新的像素缓冲区,并通知它们动画帧已完成。voidnewPixels(byte[] newpix, ColorModel newmodel, int offset, int scansize)更改新的字节数组以保存此图像的像素。voidnewPixels(int[] newpix, ColorModel newmodel, int offset, int scansize)更改为新的int数组以保存此图像的像素。voidnewPixels(int x, int y, int w, int h)将像素缓冲区的矩形区域发送到当前对此图像的数据感兴趣的任何ImageConsumers,并通知它们动画帧已完成。voidnewPixels(int x, int y, int w, int h, boolean framenotify)将像素缓冲区的矩形区域发送到当前对此图像的数据感兴趣的任何ImageConsumers。voidremoveConsumer(ImageConsumer ic)从对此图像的数据感兴趣的使用者列表中删除ImageConsumer。voidrequestTopDownLeftRightResend(ImageConsumer ic)请求给定的ImageConsumer以自上而下,左右顺序再次传递图像数据。voidsetAnimated(boolean animated)根据动画参数将此内存图像更改为多帧动画或单帧静态图像。voidsetFullBufferUpdates(boolean fullbuffers)指定是否应始终通过在发生更改时发送完整的像素缓冲区来更新此动画内存图像。voidstartProduction(ImageConsumer ic)将ImageConsumer添加到对此图像的数据感兴趣的使用者列表中,并立即通过ImageConsumer界面开始传送图像数据。
-
-
-
构造方法详细信息
-
MemoryImageSource
public MemoryImageSource(int w, int h, ColorModel cm, byte[] pix, int off, int scan)构造一个ImageProducer对象,该对象使用字节数组为Image对象生成数据。- 参数
-
w- 像素矩形的宽度 -
h- 像素矩形的高度 -
cm- 指定的ColorModel -
pix- 像素数组 -
off- 存储第一个像素的数组的偏移量 -
scan- 数组中一行像素到下一行像素的距离 - 另请参见:
-
Component.createImage(java.awt.image.ImageProducer)
-
MemoryImageSource
public MemoryImageSource(int w, int h, ColorModel cm, byte[] pix, int off, int scan, Hashtable<?,?> props)构造一个ImageProducer对象,该对象使用字节数组为Image对象生成数据。- 参数
-
w- 像素矩形的宽度 -
h- 像素矩形的高度 -
cm- 指定的ColorModel -
pix- 像素数组 -
off- 存储第一个像素的数组的偏移量 -
scan- 数组中从一行像素到下一行像素的距离 -
props-ImageProducer用于处理图像的属性列表 - 另请参见:
-
Component.createImage(java.awt.image.ImageProducer)
-
MemoryImageSource
public MemoryImageSource(int w, int h, ColorModel cm, int[] pix, int off, int scan)构造一个ImageProducer对象,该对象使用整数数组为Image对象生成数据。- 参数
-
w- 像素矩形的宽度 -
h- 像素矩形的高度 -
cm- 指定的ColorModel -
pix- 像素数组 -
off- 存储第一个像素的数组的偏移量 -
scan- 数组中从一行像素到下一行像素的距离 - 另请参见:
-
Component.createImage(java.awt.image.ImageProducer)
-
MemoryImageSource
public MemoryImageSource(int w, int h, ColorModel cm, int[] pix, int off, int scan, Hashtable<?,?> props)构造一个ImageProducer对象,该对象使用整数数组为Image对象生成数据。- 参数
-
w- 像素矩形的宽度 -
h- 像素矩形的高度 -
cm- 指定的ColorModel -
pix- 像素数组 -
off- 存储第一个像素的数组的偏移量 -
scan- 数组中从一行像素到下一行像素的距离 -
props-ImageProducer用于处理图像的属性列表 - 另请参见:
-
Component.createImage(java.awt.image.ImageProducer)
-
MemoryImageSource
public MemoryImageSource(int w, int h, int[] pix, int off, int scan)构造一个ImageProducer对象,该对象使用默认RGB ColorModel中的整数数组来为Image对象生成数据。- 参数
-
w- 像素矩形的宽度 -
h- 像素矩形的高度 -
pix- 像素数组 -
off- 存储第一个像素的数组的偏移量 -
scan- 数组中从一行像素到下一行像素的距离 - 另请参见:
-
Component.createImage(java.awt.image.ImageProducer),ColorModel.getRGBdefault()
-
MemoryImageSource
public MemoryImageSource(int w, int h, int[] pix, int off, int scan, Hashtable<?,?> props)构造一个ImageProducer对象,该对象使用默认RGB ColorModel中的整数数组来为Image对象生成数据。- 参数
-
w- 像素矩形的宽度 -
h- 像素矩形的高度 -
pix- 像素数组 -
off- 存储第一个像素的数组的偏移量 -
scan- 数组中从一行像素到下一行像素的距离 -
props-ImageProducer用于处理图像的属性列表 - 另请参见:
-
Component.createImage(java.awt.image.ImageProducer),ColorModel.getRGBdefault()
-
-
方法详细信息
-
addConsumer
public void addConsumer(ImageConsumer ic)
将ImageConsumer添加到对此图像的数据感兴趣的使用者列表中。- Specified by:
-
addConsumer接口ImageProducer - 参数
-
ic- 指定的ImageConsumer - 异常
-
NullPointerException- 如果指定的ImageConsumer为空 - 另请参见:
-
ImageConsumer
-
isConsumer
public boolean isConsumer(ImageConsumer ic)
确定ImageConsumer是否位于当前对此图像的数据感兴趣的使用者列表中。- Specified by:
-
isConsumerin interfaceImageProducer - 参数
-
ic- 指定的ImageConsumer - 结果
-
true如果ImageConsumer在列表中; 否则为false。 - 另请参见:
-
ImageConsumer
-
removeConsumer
public void removeConsumer(ImageConsumer ic)
从对此图像的数据感兴趣的使用者列表中删除ImageConsumer。- Specified by:
-
removeConsumer在界面ImageProducer - 参数
-
ic- 指定的ImageConsumer - 另请参见:
-
ImageConsumer
-
startProduction
public void startProduction(ImageConsumer ic)
将ImageConsumer添加到对此图像的数据感兴趣的使用者列表中,并立即通过ImageConsumer界面开始传送图像数据。- Specified by:
-
startProductionin interfaceImageProducer - 参数
-
ic- 通过ImageConsumer接口指定的ImageConsumer图像数据。 - 另请参见:
-
ImageConsumer
-
requestTopDownLeftRightResend
public void requestTopDownLeftRightResend(ImageConsumer ic)
请求给定的ImageConsumer以自上而下,左右顺序再次传递图像数据。- Specified by:
-
requestTopDownLeftRightResend接口ImageProducer - 参数
-
ic- 指定的ImageConsumer - 另请参见:
-
ImageConsumer
-
setAnimated
public void setAnimated(boolean animated)
根据动画参数将此内存图像更改为多帧动画或单帧静态图像。应该在构造MemoryImageSource之后以及使用它创建图像之前立即调用此方法,以确保所有ImageConsumer都将接收正确的多帧数据。 如果在设置此标志之前将ImageConsumer添加到此ImageProducer,则ImageConsumer将仅查看连接时可用的像素数据的快照。
- 参数
-
animated-true如果图像是多帧动画
-
setFullBufferUpdates
public void setFullBufferUpdates(boolean fullbuffers)
指定是否应始终通过在发生更改时发送完整的像素缓冲区来更新此动画内存图像。 如果未通过setAnimated()方法打开动画标志,则忽略此标志。应该在构造MemoryImageSource之后以及使用它创建图像之前立即调用此方法,以确保所有ImageConsumer都将接收正确的像素传递提示。
- 参数
-
fullbuffers-true如果应始终发送完整的像素缓冲区 - 另请参见:
-
setAnimated(boolean)
-
newPixels
public void newPixels()
向当前对此图像的数据感兴趣的任何ImageConsumers发送一个全新的像素缓冲区,并通知它们动画帧已完成。 仅当通过setAnimated()方法打开动画标志时,此方法才有效。
-
newPixels
public void newPixels(int x, int y, int w, int h)将像素缓冲区的矩形区域发送到当前对此图像的数据感兴趣的任何ImageConsumers,并通知它们动画帧已完成。 仅当通过setAnimated()方法打开动画标志时,此方法才有效。 如果使用setFullBufferUpdates()方法打开完整缓冲区更新标志,则将忽略矩形参数,并始终发送整个缓冲区。- 参数
-
x- 要发送的像素矩形左上角的x坐标 -
y- 要发送的像素矩形左上角的y坐标 -
w- 要发送的像素矩形的宽度 -
h- 要发送的像素矩形的高度 - 另请参见:
-
newPixels(int, int, int, int, boolean),ImageConsumer,setAnimated(boolean),setFullBufferUpdates(boolean)
-
newPixels
public void newPixels(int x, int y, int w, int h, boolean framenotify)将像素缓冲区的矩形区域发送到当前对此图像的数据感兴趣的任何ImageConsumers。 如果framenotify参数为true,则还通知消费者动画帧已完成。 仅当通过setAnimated()方法打开动画标志时,此方法才有效。 如果使用setFullBufferUpdates()方法打开完整缓冲区更新标志,则将忽略矩形参数,并始终发送整个缓冲区。- 参数
-
x- 要发送的像素矩形左上角的x坐标 -
y- 要发送的像素矩形左上角的y坐标 -
w- 要发送的像素矩形的宽度 -
h- 要发送的像素矩形的高度 -
framenotify-true如果应向消费者发送SINGLEFRAMEDONE通知 - 另请参见:
-
ImageConsumer,setAnimated(boolean),setFullBufferUpdates(boolean)
-
newPixels
public void newPixels(byte[] newpix, ColorModel newmodel, int offset, int scansize)更改新的字节数组以保存此图像的像素。 如果通过setAnimated()方法打开了动画标志,则新像素将立即传递给当前对此图像数据感兴趣的任何ImageConsumers。- 参数
-
newpix- 新的像素阵列 -
newmodel- 指定的ColorModel -
offset- 数组的偏移量 -
scansize- 数组中从一行像素到下一行像素的距离 - 另请参见:
-
newPixels(int, int, int, int, boolean),setAnimated(boolean)
-
newPixels
public void newPixels(int[] newpix, ColorModel newmodel, int offset, int scansize)更改为新的int数组以保存此图像的像素。 如果通过setAnimated()方法打开了动画标志,则新像素将立即传递给当前对此图像数据感兴趣的任何ImageConsumers。- 参数
-
newpix- 新的像素阵列 -
newmodel- 指定的ColorModel -
offset- 数组的偏移量 -
scansize- 数组中从一行像素到下一行像素的距离 - 另请参见:
-
newPixels(int, int, int, int, boolean),setAnimated(boolean)
-
-