所有类


java.awt.image
类 MemoryImageSource

java.lang.Object
  继承者 java.awt.image.MemoryImageSource
所有已实现的接口:
ImageProducer

public class MemoryImageSource
   
   
   
   
   
extends Object
implements ImageProducer

此类是 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 对象。
 
方法摘要
 voidaddConsumer(ImageConsumer ic)
          将 ImageConsumer 添加到对此图像数据感兴趣的使用者列表。
 booleanisConsumer(ImageConsumer ic)
          确定某个 ImageConsumer 目前是否处于对此图像数据感兴趣的使用者列表中。
 voidnewPixels()
          将全部的新像素缓冲区发送到所有目前对此图像数据感兴趣的 ImageConsumer,并通知这些 ImageConsumer 一个动画帧已完成。
 voidnewPixels(byte[] newpix, ColorModel newmodel, int offset, int scansize)
          改用一个新的 byte 数组以保存此图像的像素。
 voidnewPixels(int[] newpix, ColorModel newmodel, int offset, int scansize)
          改用一个新的 int 数组以保存此图像的像素。
 voidnewPixels(int x, int y, int w, int h)
          将像素缓冲区的矩形区域发送到所有目前对此图像数据感兴趣的 ImageConsumer,并通知这些 ImageConsumer 一个动画帧已完成。
 voidnewPixels(int x, int y, int w, int h, boolean framenotify)
          将像素缓冲区的矩形区域发送到所有目前对此图像数据感兴趣的 ImageConsumer。
 voidremoveConsumer(ImageConsumer ic)
          从对此图像数据感兴趣的使用者列表中移除 ImageConsumer。
 voidrequestTopDownLeftRightResend(ImageConsumer ic)
          请求给定的 ImageConsumer 再次按从上到下、从左到右的顺序传递图像数据。
 voidsetAnimated(boolean animated)
          根据 animated 参数将此内存图像更改为多帧动画或单帧静态图像。
 voidsetFullBufferUpdates(boolean fullbuffers)
          指定在像素缓冲区发生变化时,是否总是通过发送完整的缓冲区来更新此动画内存图像。
 voidstartProduction(ImageConsumer ic)
          将 ImageConsumer 添加到对此图像数据感兴趣的使用者列表中,并立即开始通过 ImageConsumer 接口传递图像数据。
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

MemoryImageSource

public MemoryImageSource(int w,
                         int h,
                         ColorModel cm,
                         byte[] pix,
                         int off,
                         int scan)
构造一个使用 byte 数组为 Image 对象生成数据的 ImageProducer 对象。

参数:
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)
构造一个使用 byte 数组为 Image 对象生成数据的 ImageProducer 对象。

参数:
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)
构造一个使用整数数组为 Image 对象生成数据的 ImageProducer 对象。

参数:
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)
构造一个使用整数数组为 Image 对象生成数据的 ImageProducer 对象。

参数:
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)
构造一个使用默认 RGB ColorModel 中的整数数组为 Image 对象生成数据的 ImageProducer 对象。

参数:
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)
构造一个使用默认 RGB ColorModel 中的整数数组为 Image 对象生成数据的 ImageProducer 对象。

参数:
w - 像素矩形的宽度
h - 像素矩形的高度
pix - 一个像素数组
off - 数组中存储首个像素的偏移量
scan - 数组中一行像素到下一行像素之间的距离
props - ImageProducer 用于处理图像的属性列表
另请参见:
Component.createImage(java.awt.image.ImageProducer), ColorModel.getRGBdefault()
方法详细信息

addConsumer

public void addConsumer(ImageConsumer ic)
将 ImageConsumer 添加到对此图像数据感兴趣的使用者列表。

指定者:
接口 ImageProducer 中的 addConsumer
参数:
ic - 指定的 ImageConsumer
抛出:
NullPointerException - 如果指定的 ImageConsumer 为 null
另请参见:
ImageConsumer

isConsumer

public boolean isConsumer(ImageConsumer ic)
确定某个 ImageConsumer 目前是否处于对此图像数据感兴趣的使用者列表中。

指定者:
接口 ImageProducer 中的 isConsumer
参数:
ic - 指定的 ImageConsumer
返回:
如果该 ImageConsumer 处于列表中,则返回 true;否则返回 false
另请参见:
ImageConsumer