Package java.awt.image |
![]() Previous |
![]() Java API |
![]() Index |
![]() Next |
public class java.awt.image.MemoryImageSource extends java.lang.Object implements java.awt.image.ImageProducer { // Constructors public MemoryImageSource(int w, int h, ColorModel cm, byte pix[], int off, int scan); public MemoryImageSource(int w, int h, ColorModel cm, byte pix[], int off, int scan, ; Hashtable props); public MemoryImageSource(int w, int h, ColorModel cm, int pix[], int off, int scan); public MemoryImageSource(int w, int h, ColorModel cm, int pix[], int off, int scan, Hashtable props); public MemoryImageSource(int w, int h, int pix[], int off, int scan); public MemoryImageSource(int w, int h, int pix[], int off, int scan, Hashtable props); // Methods public void addConsumer(ImageConsumer ic); public boolean isConsumer(ImageConsumer ic); public void removeConsumer(ImageConsumer ic); public void requestTopDownLeftRightResend(ImageConsumer ic); public void startProduction(ImageConsumer ic); }
A memory image source is an implementation of the image producer interface . It uses an array to produce pixel values for the image.
Here is an example which calculates a 100 ´ 100 image representing a fade from black to blue along the X axis and from black to red along the Y axis:
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));
An application can use the method createImage in class Component to create an Image from a MemoryImageSource.
public MemoryImageSource(int w, int h, ColorModel cm, byte pix[], int off, int scan)Constructs an image producer object which uses an array of bytes to produce data for the image object. The pixel at coordinate (i,j) is stored in the pixel array at index j ´ scan + i + offset.
Parameter Description w the width of the image h the height of the image cm the color model used the pixels pix the array of pixel values off the offset of the first pixel in the array scan the number of pixels in the array per line
public MemoryImageSource(int w, int h, ColorModel cm, byte pix[], int off, int scan, Hashtable props)Constructs an image producer object which uses an array of bytes to produce data for the image object. The pixel at coordinate (i,j) is stored in the pixel array at index j ´ scan + i + offset.
In addition, the image has the properties indicated in the hash table argument.
Parameter Description w the width of the image h the height of the image cm the color model used the pixels pix the array of pixel values off the offset of the first pixel in the array scan the number of pixels in the array per line props a hash table of properties
public MemoryImageSource(int w, int h, ColorModel cm, int pix[], int off, int scan)Constructs an image producer object which uses an array of integers to produce data for the image object. The pixel at coordinate (i,j) is stored in the pixel array at index j ´ scan + i + offset.
Parameter Description w the width of the image h the height of the image cm the color model used the pixels pix the array of pixel values off the offset of the first pixel in the array scan the number of pixels in the array per line
public MemoryImageSource(int w, int h, ColorModel cm, int pix[], int off, int scan, Hashtable props)Constructs an image producer object which uses an array of integers to produce data for the image object. The pixel at coordinate (i,j) is stored in the pixel array at index j ´ scan + i + offset.
In addition, the image has the properties indicated in the hash table argument.
Parameter Description w the width of the image h the height of the image cm the color model used the pixels pix the array of pixel values off the offset of the first pixel in the array scan the number of pixels in the array per line props a hash table of properties
public MemoryImageSource(int w, int h, int pix[], int off, int scan)Constructs an image producer object which uses an array of integers to produce data for the image object. The pixel at coordinate (i,j) is stored in the pixel array at index j ´ scan + i + offset.
The resulting image uses the default RGB color model .
Parameter Description w the width of the image h the height of the image pix the array of pixel values off the offset of the first pixel in the array scan the number of pixels in the array per line
public MemoryImageSource(int w, int h, int pix[], int off, int scan, Hashtable props)Constructs an image producer object which uses an array of integers to produce data for the image object. The pixel at coordinate (i,j) is stored in the pixel array at index j ´ scan + i + offset. The resulting image uses the default RGB color model .
In addition, the image has the properties indicated in the hash table argument.
Parameter Description w the width of the image h the height of the image cm the color model used the pixels pix the array of pixel values off the offset of the first pixel in the array scan the number of pixels in the array per line props a hash table of properties
public void addConsumer(ImageConsumer ic)Registers the image consumer argument as wanting the image produced by this image producer. For more information on this method and its arguments, see addConsumer.
The addConsumer method of MemoryImageSource, since it already has the image data, immediately delivers the data to the image consumer.
Parameter Description ic an image consumer
public boolean isConsumer(ImageConsumer ic)Determines if the image consumer argument is registered with this image producer as a consumer. Because the memory image source delivers data immediately to its image consumer, the memory image source can have at most one consumer at a time.
Return Value:
Returns true if the specified image consumer argument is currently registered with this image producer as one of its consumers; false otherwise.
Parameter Description ic an image consumer
public void removeConsumer(ImageConsumer ic)Removes the specified image consumer object from the list of consumers registered to receive the image data. For more information on this method and its arguments, see removeConsumer.
Parameter Description ic an image consumer
public void requestTopDownLeftRightResend(ImageConsumer ic)An image consumer sends this message to request that the image producer attempt to resend the image data one more time in top-down, left-to-right order. For more information on this method and its arguments, see requestTopDownLeftRightResend.
The requestTopDownLeftRightResend method of memoryImageSource ignores this request, since it always sends its data in that order.
Parameter Description ic an image consumer
public void startProduction(ImageConsumer ic)Registers the image consumer argument as wanting the image produced by this image producer. In addition, this method forces the image producer to start an immediate reconstruction of the image data For more information on this method and its arguments, see startProduction.
The addConsumer method of MemoryImageSource, since it already has the image data, immediately delivers the data to the image consumer.
Parameter Description ic an image consumer