Package java.awt.image Previous
Previous
Java API
Java API
Index
Index
Next
Next

Class MemoryImageSource

Constructors , Methods

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.


Constructors


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.

ParameterDescription
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


MemoryImageSource

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.

ParameterDescription
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


MemoryImageSource

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.

ParameterDescription
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


MemoryImageSource

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.

ParameterDescription
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


MemoryImageSource

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 .

ParameterDescription
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


MemoryImageSource

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.

ParameterDescription
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


Methods


addConsumer

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.

ParameterDescription
ic an image consumer


isConsumer

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.

ParameterDescription
ic an image consumer


removeConsumer

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.

ParameterDescription
ic an image consumer


requestTopDownLeftRightResend

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.

ParameterDescription
ic an image consumer


startProduction

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.

ParameterDescription
ic an image consumer



Top© 1996 Sun Microsystems, Inc. All rights reserved.