Text of docs.oracle.com › en › java › javase › 11 › docs › api › java.desktop › java › awt › image › PixelG… as Styx crawled it on Nov 19, 2026. The page may have changed since. Only its words are kept, without pictures or layout, and only the first part of a long page.

Open the live page

PixelGrabber (Java SE 11 & JDK 11 )

Module java.desktop Package java.awt.image Class PixelGrabber java.lang.Object java.awt.image.PixelGrabber All Implemented Interfaces: ImageConsumer 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 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 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.getStatus() & 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]); } } } See Also: ColorModel.getRGBdefault() Field Summary Fields declared in interface java.awt.image.

ImageConsumer COMPLETESCANLINES , IMAGEABORTED , IMAGEERROR , RANDOMPIXELORDER , SINGLEFRAME , SINGLEFRAMEDONE , SINGLEPASS , STATICIMAGEDONE , TOPDOWNLEFTRIGHT Constructor Summary Constructors Constructor Description 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.

PixelGrabber ​( Image img, int x, int y, int w, int h, boolean forceRGB) Create a PixelGrabber object to grab the (x, y, w, h) rectangular section of pixels from the specified image. 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. Method Summary All Methods Instance Methods Concrete Methods Modifier and Type Method Description void abortGrabbing () Request the PixelGrabber to abort the image fetch.

ColorModel getColorModel () Get the ColorModel for the pixels stored in the array. int getHeight () Get the height of the pixel buffer (after adjusting for image height). Object getPixels () Get the pixel buffer. int getStatus () Return the status of the pixels. int getWidth () Get the width of the pixel buffer (after adjusting for image width). boolean 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. boolean grabPixels ​(long ms) 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. void imageComplete ​(int status) The imageComplete method is part of the ImageConsumer API which this class must implement to retrieve the pixels. void setColorModel ​( ColorModel model) The setColorModel method is part of the ImageConsumer API which this class must implement to retrieve the pixels. void setDimensions ​(int width, int height) The setDimensions method is part of the ImageConsumer API which this class must implement to retrieve the pixels. void setHints ​(int hints) The setHints method is part of the ImageConsumer API which this class must implement to retrieve the pixels. 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. 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. void setProperties ​( Hashtable <?,​?> props) The setProperties method is part of the ImageConsumer API which this class must implement to retrieve the pixels. void startGrabbing () Request the PixelGrabber to start fetching the pixels. int status () Returns the status of the pixels.

Methods declared in class java.lang. Object clone , equals , finalize , getClass , hashCode , notify , notifyAll , toString , wait , wait , wait Constructor Detail 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: ColorModel.getRGBdefault() 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: ip - the ImageProducer that produces the image from which to retrieve pixels 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: ColorModel.getRGBdefault() PixelGrabber public PixelGrabber​( Image img, int x, int y, int w, int h, boolean forceRGB) Create a PixelGrabber object to grab the (x, y, w, h) rectangular section of pixels from the specified image.

The pixels are accumulated in the original ColorModel if the same ColorModel is used for every call to setPixels, otherwise the pixels are accumulated in the default RGB ColorModel. If the forceRGB parameter is true, then the pixels will be accumulated in the default RGB ColorModel anyway. A buffer is allocated by the PixelGrabber to hold the pixels in either case. If (w < 0) or (h < 0) , then they will default to the remaining width and height of the source data when that information is delivered.

Parameters: img - the image to retrieve the image data 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 retr

The rest of this page is on the live site.