|
Java™ Platform Standard Ed. 6 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.image.PixelGrabber
public class PixelGrabber
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]); } } }
ColorModel.getRGBdefault()
Field Summary |
---|
Fields inherited from interface java.awt.image.ImageConsumer |
---|
COMPLETESCANLINES, IMAGEABORTED, IMAGEERROR, RANDOMPIXELORDER, SINGLEFRAME, SINGLEFRAMEDONE, SINGLEPASS, STATICIMAGEDONE, TOPDOWNLEFTRIGHT |
Constructor Summary | |
---|---|
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. |
|
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. |
Method Summary | |
---|---|
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 inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public PixelGrabber(Image img, int x, int y, int w, int h, int[] pix, int off, int scansize)
img
- the image to retrieve pixels fromx
- 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 imagey
- the y coordinate of the upper left corner of the rectangle
of pixels to retrieve from the imagew
- the width of the rectangle of pixels to retrieveh
- the height of the rectangle of pixels to retrievepix
- the array of integers which are to be used to hold the
RGB pixels retrieved from the imageoff
- the offset into the array of where to store the first pixelscansize
- the distance from one row of pixels to the next in
the arrayColorModel.getRGBdefault()
public PixelGrabber(ImageProducer ip, int x, int y, int w, int h, int[] pix, int off, int scansize)
ip
- the ImageProducer
that produces the
image from which to retrieve pixelsx
- 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 imagey
- the y coordinate of the upper left corner of the rectangle
of pixels to retrieve from the imagew
- the width of the rectangle of pixels to retrieveh
- the height of the rectangle of pixels to retrievepix
- the array of integers which are to be used to hold the
RGB pixels retrieved from the imageoff
- the offset into the array of where to store the first pixelscansize
- the distance from one row of pixels to the next in
the arrayColorModel.getRGBdefault()
public PixelGrabber(Image img, int x, int y, int w, int h, boolean forceRGB)
img
- the image to retrieve the image data fromx
- 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 imagey
- the y coordinate of the upper left corner of the rectangle
of pixels to retrieve from the imagew
- the width of the rectangle of pixels to retrieveh
- the height of the rectangle of pixels to retrieveforceRGB
- true if the pixels should always be converted to
the default RGB ColorModelMethod Detail |
---|
public void startGrabbing()
public void abortGrabbing()
public boolean grabPixels() throws InterruptedException
InterruptedException
- Another thread has interrupted this thread.public boolean grabPixels(long ms) throws InterruptedException
ms
:
ms
== 0, waits until all pixels are delivered
ms
> 0, waits until all pixels are delivered
as timeout expires.
ms
< 0, returns true
if all pixels
are grabbed, false
otherwise and does not wait.
ms
- the number of milliseconds to wait for the image pixels
to arrive before timing out
InterruptedException
- Another thread has interrupted this thread.public int getStatus()
ImageObserver
public int getWidth()
getStatus()
public int getHeight()
getStatus()
public Object getPixels()
getStatus()
,
setPixels(int, int, int, int, ColorModel, byte[], int, int)
,
setPixels(int, int, int, int, ColorModel, int[], int, int)
public ColorModel getColorModel()
getStatus()
,
ColorModel.getRGBdefault()
,
setColorModel(ColorModel)
public void setDimensions(int width, int height)
Note: This method is intended to be called by the ImageProducer of the Image whose pixels are being grabbed. Developers using this class to retrieve pixels from an image should avoid calling this method directly since that operation could result in problems with retrieving the requested pixels.
setDimensions
in interface ImageConsumer
width
- the width of the dimensionheight
- the height of the dimensionpublic void setHints(int hints)
Note: This method is intended to be called by the ImageProducer of the Image whose pixels are being grabbed. Developers using this class to retrieve pixels from an image should avoid calling this method directly since that operation could result in problems with retrieving the requested pixels.
setHints
in interface ImageConsumer
hints
- a set of hints used to process the pixelspublic void setProperties(Hashtable<?,?> props)
Note: This method is intended to be called by the ImageProducer of the Image whose pixels are being grabbed. Developers using this class to retrieve pixels from an image should avoid calling this method directly since that operation could result in problems with retrieving the requested pixels.
setProperties
in interface ImageConsumer
props
- the list of propertiespublic void setColorModel(ColorModel model)
Note: This method is intended to be called by the ImageProducer of the Image whose pixels are being grabbed. Developers using this class to retrieve pixels from an image should avoid calling this method directly since that operation could result in problems with retrieving the requested pixels.
setColorModel
in interface ImageConsumer
model
- the specified ColorModel
getColorModel()
public void setPixels(int srcX, int srcY, int srcW, int srcH, ColorModel model, byte[] pixels, int srcOff, int srcScan)
Note: This method is intended to be called by the ImageProducer of the Image whose pixels are being grabbed. Developers using this class to retrieve pixels from an image should avoid calling this method directly since that operation could result in problems with retrieving the requested pixels.
setPixels
in interface ImageConsumer
srcX
- the X coordinate of the upper-left corner
of the area of pixels to be setsrcY
- the Y coordinate of the upper-left corner
of the area of pixels to be setsrcW
- the width of the area of pixelssrcH
- the height of the area of pixelsmodel
- the specified ColorModel
pixels
- the array of pixelssrcOff
- the offset into the pixels arraysrcScan
- the distance from one row of pixels to the next
in the pixels arraygetPixels()
public void setPixels(int srcX, int srcY, int srcW, int srcH, ColorModel model, int[] pixels, int srcOff, int srcScan)
Note: This method is intended to be called by the ImageProducer of the Image whose pixels are being grabbed. Developers using this class to retrieve pixels from an image should avoid calling this method directly since that operation could result in problems with retrieving the requested pixels.
setPixels
in interface ImageConsumer
srcX
- the X coordinate of the upper-left corner
of the area of pixels to be setsrcY
- the Y coordinate of the upper-left corner
of the area of pixels to be setsrcW
- the width of the area of pixelssrcH
- the height of the area of pixelsmodel
- the specified ColorModel
pixels
- the array of pixelssrcOff
- the offset into the pixels arraysrcScan
- the distance from one row of pixels to the next
in the pixels arraygetPixels()
public void imageComplete(int status)
Note: This method is intended to be called by the ImageProducer of the Image whose pixels are being grabbed. Developers using this class to retrieve pixels from an image should avoid calling this method directly since that operation could result in problems with retrieving the requested pixels.
imageComplete
in interface ImageConsumer
status
- the status of image loadingImageProducer.removeConsumer(java.awt.image.ImageConsumer)
public int status()
getStatus
have the
same implementation, but getStatus
is the
preferred method because it conforms to the convention of
naming information-retrieval methods with the form
"getXXX".
ImageObserver
,
getStatus()
|
Java™ Platform Standard Ed. 6 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright © 1993, 2015, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.