Packages  This Package  Prev  Next  Index  
	§2.7 Class MemoryImageSource
public  class  java.awt.image.MemoryImageSource
    extends  java.lang.Object  (I-§1.12)
    implements java.awt.image.ImageProducer  (II-§2.12)
{
        // Constructors
    public MemoryImageSource(int  w, int  h, ColorModel cm, 	§2.7.1
                                byte  pix[], int  off,  int  scan);
    public MemoryImageSource(int  w, int  h, ColorModel cm, 	§2.7.2
                                byte  pix[], int  off,  int  scan,
 ;                          Hashtable  props);
    public MemoryImageSource(int  w, int  h, ColorModel cm, 	§2.7.3
                              int  pix[], int  off,  int  scan);
    public MemoryImageSource(int  w, int  h, ColorModel cm,	§2.7.4
                int  pix[], int  off, int scan, 
                                Hashtable  props);
    public MemoryImageSource(int  w, int  h, int pix[], 	§2.7.5
                               int off, int  scan);
    public MemoryImageSource(int  w, int  h, int pix[], 	§2.7.6
                        int  off, int scan, 
                                Hashtable  props);
        // Methods
    public void addConsumer(ImageConsumer  ic);	§2.7.7
    public boolean isConsumer(ImageConsumer  ic);	§2.7.8
    public void removeConsumer(ImageConsumer  ic);	§2.7.9
    public void	     §2.7.10
        requestTopDownLeftRightResend(ImageConsumer  ic);
    public void startProduction(ImageConsumer  ic);	§2.7.11
}
A memory image source is an implementation of the image producer interface (II-§2.12). 
It uses an array to produce pixel values for the image. 
Here is an example which calculates a 
 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  (II-§1.10.6) to create an 
Image from a MemoryImageSource.
The method 
MemoryImageSource
public
MemoryImageSource(int  w, int  h, ColorModel  cm,
                                    byte  pix[], int  off, int  scan)
- Constructs an image producer (II-§2.12) object which uses an array of 
bytes to produce data for the image object. The pixel at coordinate 
 
is stored in the pixel array at index 
.
- Parameters:
 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 (II-§2.12) object which uses an array of 
bytes to produce data for the image object. The pixel at coordinate 
 
is stored in the pixel array at index 
.
- In addition, the image has the properties indicated in the hash table argument.
- Parameters:
 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 (II-§2.12) object which uses an array of 
integers to produce data for the image object. The pixel at coordinate 
 is stored in the pixel array at index 
.
- Parameters:
 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 (II-§2.12) object which uses an array of 
integers to produce data for the image object. The pixel at coordinate 
 is stored in the pixel array at index 
.
- In addition, the image has the properties indicated in the hash table argument.
- Parameters:
 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 (II-§2.12) object which uses an array of 
integers to produce data for the image object. The pixel at coordinate 
 is stored in the pixel array at index 
.
- The resulting image uses the default RGB color model (II-§2.1.9).
- Parameters:
 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 (II-§2.12) object which uses an array of 
integers to produce data for the image object. The pixel at coordinate 
 is stored in the pixel array at index 
. The 
resulting image uses the default RGB color model (II-§2.1.9).
- In addition, the image has the properties indicated in the hash table argument.
- Parameters:
 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
  
addConsumer
public void addConsumer(ImageConsumer  ic)
- Registers the image consumer (II-§2.10) argument as wanting the image 
produced by this image producer. For more information on this method 
and its arguments, see §2.12.1 on page  313.
- The addConsumer method of MemoryImageSource, since it already has the 
image data, immediately delivers the data to the image consumer.
- Parameters:
 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.
- Parameters:
 ic
- an image consumer
- Returns:
 - true if the specified image consumer argument (II-§2.10) is currently 
registered with this image producer as one of its consumers; false otherwise.
 
 
removeConsumer
public void removeConsumer(ImageConsumer  ic)
- Removes the specified image consumer (II-§2.10) object from the list of 
consumers registered to receive the image data. For more information on 
this method and its arguments, see §2.12.3 on page  314.
- Parameters:
 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 §2.12.4 
on page  314.
- The requestTopDownLeftRightResend method of memoryImageSource ignores 
this request, since it always sends its data in that order.
- Parameters:
 ic
- an image consumer
  
startProduction
public void startProduction(ImageConsumer  ic)
- Registers the image consumer (II-§2.10) 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 §2.12.5 on 
page  314.
- The addConsumer method of MemoryImageSource, since it already has the 
image data, immediately delivers the data to the image consumer.
- Parameters:
 ic
- an image consumer
  
Packages  This Package  Prev  Next  Index
Java API Document (HTML generated by dkramer on April 22, 1996)
Copyright © 1996 Sun Microsystems, Inc.
All rights reserved
Please send any comments or corrections to doug.kramer@sun.com