Class java.awt.image.PixelGrabber
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class java.awt.image.PixelGrabber

java.lang.Object
   |
   +----java.awt.image.PixelGrabber

public class PixelGrabber
extends Object
implements ImageConsumer
The PixelGrabber class implements an ImageConsumer which can be attached to an Image or ImageProducer object to retrieve a subset of the pixels in that image. Here is an example:
public abstract void handlesinglepixel(int x, int y, int pixel);
public void handlepixels(Image img, int x, int y, int w, int h) {
	int[] pixels = new int[w * h];
	PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w);
	try {
	    pg.grabPixels();
	} catch (InterruptedException e) {
	    System.err.println("interrupted waiting for pixels!");
	    return;
	}
	if ((pg.status() & ImageObserver.ABORT) != 0) {
	    System.err.println("image fetch aborted or errored");
	    return;
	}
	for (int j = 0; j < h; j++) {
	    for (int i = 0; i < w; i++) {
		handlesinglepixel(x+i, y+j, pixels[j * w + i]);
	    }
	}
}

Constructor Index

 o PixelGrabber(Image, int, int, int, int, int[], int, int)
Create a PixelGrabber object to grab the (x, y, w, h) rectangular section of pixels from the specified image into the given array.
 o PixelGrabber(ImageProducer, int, int, int, int, int[], int, int)
Create a PixelGrabber object to grab the (x, y, w, h) rectangular section of pixels from the image produced by the specified ImageProducer into the given array.

Method Index

 o grabPixels()
Request the Image or ImageProducer to start delivering pixels and wait for all of the pixels in the rectangle of interest to be delivered.
 o grabPixels(long)
Request the Image or ImageProducer to start delivering pixels and wait for all of the pixels in the rectangle of interest to be delivered or until the specified timeout has elapsed.
 o imageComplete(int)
The imageComplete method is part of the ImageConsumer API which this class must implement to retrieve the pixels.
 o setColorModel(ColorModel)
The setColorModel method is part of the ImageConsumer API which this class must implement to retrieve the pixels.
 o setDimensions(int, int)
The setDimensions method is part of the ImageConsumer API which this class must implement to retrieve the pixels.
 o setHints(int)
The setHints method is part of the ImageConsumer API which this class must implement to retrieve the pixels.
 o setPixels(int, int, int, int, ColorModel, byte[], int, int)
The setPixels method is part of the ImageConsumer API which this class must implement to retrieve the pixels.
 o setPixels(int, int, int, int, ColorModel, int[], int, int)
The setPixels method is part of the ImageConsumer API which this class must implement to retrieve the pixels.
 o setProperties(Hashtable)
The setProperties method is part of the ImageConsumer API which this class must implement to retrieve the pixels.
 o status()
Return the status of the pixels.

Constructors

 o PixelGrabber
  public PixelGrabber(Image img,
                      int x,
                      int y,
                      int w,
                      int h,
                      int pix[],
                      int off,
                      int scansize)
Create a PixelGrabber object to grab the (x, y, w, h) rectangular section of pixels from the specified image into the given array. The pixels are stored into the array in the default RGB ColorModel. The RGB data for pixel (i, j) where (i, j) is inside the rectangle (x, y, w, h) is stored in the array at pix[(j - y) * scansize + (i - x) + off].
Parameters:
img - the image to retrieve pixels from
x - the x coordinate of the upper left corner of the rectangle of pixels to retrieve from the image, relative to the default (unscaled) size of the image
y - the y coordinate of the upper left corner of the rectangle of pixels to retrieve from the image
w - the width of the rectangle of pixels to retrieve
h - the height of the rectangle of pixels to retrieve
pix - the array of integers which are to be used to hold the RGB pixels retrieved from the image
off - the offset into the array of where to store the first pixel
scansize - the distance from one row of pixels to the next in the array
See Also:
getRGBdefault
 o PixelGrabber
  public PixelGrabber(ImageProducer ip,
                      int x,
                      int y,
                      int w,
                      int h,
                      int pix[],
                      int off,
                      int scansize)
Create a PixelGrabber object to grab the (x, y, w, h) rectangular section of pixels from the image produced by the specified ImageProducer into the given array. The pixels are stored into the array in the default RGB ColorModel. The RGB data for pixel (i, j) where (i, j) is inside the rectangle (x, y, w, h) is stored in the array at pix[(j - y) * scansize + (i - x) + off].
Parameters:
img - the image to retrieve pixels from
x - the x coordinate of the upper left corner of the rectangle of pixels to retrieve from the image, relative to the default (unscaled) size of the image
y - the y coordinate of the upper left corner of the rectangle of pixels to retrieve from the image
w - the width of the rectangle of pixels to retrieve
h - the height of the rectangle of pixels to retrieve
pix - the array of integers which are to be used to hold the RGB pixels retrieved from the image
off - the offset into the array of where to store the first pixel
scansize - the distance from one row of pixels to the next in the array
See Also:
getRGBdefault

Methods

 o grabPixels
  public boolean grabPixels() throws InterruptedException
Request the Image or ImageProducer to start delivering pixels and wait for all of the pixels in the rectangle of interest to be delivered.
Returns:
true if the pixels were successfully grabbed, false on abort, error or timeout
Throws: InterruptedException
Another thread has interrupted this thread.
 o grabPixels
  public synchronized boolean grabPixels(long ms) throws InterruptedException
Request the Image or ImageProducer to start delivering pixels and wait for all of the pixels in the rectangle of interest to be delivered or until the specified timeout has elapsed.
Parameters:
ms - the number of milliseconds to wait for the image pixels to arrive before timing out
Returns:
true if the pixels were successfully grabbed, false on abort, error or timeout
Throws: InterruptedException
Another thread has interrupted this thread.
 o status
  public synchronized int status()
Return the status of the pixels. The ImageObserver flags representing the available pixel information are returned.
Returns:
the bitwise OR of all relevant ImageObserver flags
See Also:
ImageObserver
 o setDimensions
  public void setDimensions(int width,
                            int height)
The setDimensions method is part of the ImageConsumer API which this class must implement to retrieve the pixels.
 o setHints
  public void setHints(int hints)
The setHints method is part of the ImageConsumer API which this class must implement to retrieve the pixels.
 o setProperties
  public void setProperties(Hashtable props)
The setProperties method is part of the ImageConsumer API which this class must implement to retrieve the pixels.
 o setColorModel
  public void setColorModel(ColorModel model)
The setColorModel method is part of the ImageConsumer API which this class must implement to retrieve the pixels.
 o setPixels
  public void setPixels(int srcX,
                        int srcY,
                        int srcW,
                        int srcH,
                        ColorModel model,
                        byte pixels[],
                        int srcOff,
                        int srcScan)
The setPixels method is part of the ImageConsumer API which this class must implement to retrieve the pixels.
 o setPixels
  public void setPixels(int srcX,
                        int srcY,
                        int srcW,
                        int srcH,
                        ColorModel model,
                        int pixels[],
                        int srcOff,
                        int srcScan)
The setPixels method is part of the ImageConsumer API which this class must implement to retrieve the pixels.
 o imageComplete
  public synchronized void imageComplete(int status)
The imageComplete method is part of the ImageConsumer API which this class must implement to retrieve the pixels.

All Packages  Class Hierarchy  This Package  Previous  Next  Index