Packages This Package Prev Next Index
public class java.awt.image.PixelGrabber extends java.lang.Object (I-§1.12) implements java.awt.image.ImageConsumer (II-§2.10) { // Constructors public PixelGrabber(Image img, int x, int y, §2.8.1 int w, int h, int pix[], int off, int scansize); public PixelGrabber(ImageProducer ip, int x, §2.8.2 int y, int w, int h, int pix[], int off, int scansize); // Methods public boolean grabPixels(); §2.8.3 public boolean grabPixels(long ms); §2.8.4 public void imageComplete(int status); §2.8.5 public void setColorModel(ColorModel model); §2.8.6 public void setDimensions(int width, int height) §2.8.7 public void setHints(int hints); §2.8.8 public void setPixels(int srcX, int srcY, int srcW, §2.8.9 int srcH, ColorModel model, byte pixels[], int srcOff, int srcScan); public void setPixels(int srcX, int srcY, int srcW, §2.8.10 int srcH, ColorModel model, int pixels[], int srcOff, int srcScan); public void setProperties(Hashtable props); §2.8.11 public int status(); §2.8.12 }The pixel grabber implements an image consumer which can be attached to an image or image producer object to retrieve a subset of the pixels in that image. Pixels are stored in the array in the default RGB color model (II-§2.1.9).
Most applications need to call only the grabPixel methods (§2.8.3, §2.8.4) and the status method (II-§2.8.12) of this class. The remaining methods are part of the ImageConsumer interface and allow the pixel grabber to receive the image from the image producer.
public void handleSinglePixel(int x, int y, int pixel) { int alpha = (pixel >> 24) & 0xff; int red = (pixel >> 16) & 0xff; int green = (pixel >> 8) & 0xff; int blue = (pixel ) & 0xff; // Deal with the pixel as necessary... } public void GetPixels(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++) { // look at the pixel handleSinglePixel(x+i, y+j, pixels[j * w + i]); } } }
public PixelGrabber(Image img, int x, int y, int w, int h,
int pix[], int off, int scansize)
img
-
the image from which to retrieve pixels
x
-
the x coordinate of the upper left corner
y
-
the y coordinate of the upper left corner
w
-
the width of the rectangle to retrieve
h
-
the height of the rectangle to retrieve
pix
-
the array of integers into which to place the RGB pixels retrieved
from the image
off
-
the offset into the array to store the first pixel
scansize
-
the distance from the start of one row of pixels to the start of
the next row in the array
public PixelGrabber(ImageProducer ip, int x, int y,
int w, int h, int pix[],
int off, int scansize)
ip
-
the image producer
x
-
the x coordinate of the upper left corner
y
-
the y coordinate of the upper left corner
w
-
the width of the rectangle to retrieve
h
-
the height of the rectangle to retrieve
pix
-
the array of integers into which to place the RGB pixels retrieved
from the image
off
-
the offset into the array to store the first pixel
scansize
-
the distance from the start of one row of pixels to the start of
the next row in the array
public boolean grabPixels()
throws InterruptedException
public boolean grabPixels(long ms)
throws InterruptedException
ms
-
the number of milliseconds to wait for the pixels
public void imageComplete(int status)
status
-
the status of the image
public void setColorModel(ColorModel model)
model
-
a color map used in subsequent setPixel calls
public void setDimensions(int width, int height)
width
-
the width of the image
height
-
the height of the image
public void setHints(int hints)
hints
-
hints about the order in which the bits will be delivered
public void
setPixels(int srcX, int srcY, int srcW, int srcH,
ColorModel model, byte pixels[],
int srcOff, int srcScan)
x
-
left coordinate of rectangle
y
-
top coordinte of rectangle
w
-
width of rectangle
h
-
height of rectangle
model
-
color model for bits
pixels
-
array of bits
off
-
offset for first element
scansize
-
number of elements per row
public void
setPixels(int srcX, int srcY, int srcW, int srcH,
ColorModel model, int pixels[],
int srcOff, int srcScan)
x
-
left coordinate of rectangle
y
-
top coordinte of rectangle
w
-
width of rectangle
h
-
height of rectangle
model
-
color model for bits
pixels
-
array of bits
off
-
offset for first element
scansize
-
number of elements per row
public void setProperties(Hashtable props)
props
-
a hashtable that maps image properties to their value
public int status()
Packages This Package Prev Next IndexJava API Document (HTML generated by dkramer on April 22, 1996)