java.awt.image
public class PixelGrabber extends Object implements ImageConsumer
COMPLETESCANLINES, IMAGEABORTED, IMAGEERROR, RANDOMPIXELORDER, SINGLEFRAME, SINGLEFRAMEDONE, SINGLEPASS, STATICIMAGEDONE, TOPDOWNLEFTRIGHT
Constructor and Description |
---|
PixelGrabber(Image img,
int x,
int y,
int w,
int h,
boolean forceRGB)
Construct a PixelGrabber that will retrieve data from a given
Image.
|
PixelGrabber(Image img,
int x,
int y,
int w,
int h,
int[] pix,
int off,
int scansize)
Construct a PixelGrabber that will retrieve RGB data from a given
Image.
|
PixelGrabber(ImageProducer ip,
int x,
int y,
int w,
int h,
int[] pix,
int off,
int scansize)
Construct a PixelGrabber that will retrieve RGB data from a given
ImageProducer.
|
Modifier and Type | Method and Description |
---|---|
void |
abortGrabbing()
Abort pixel grabbing.
|
ColorModel |
getColorModel() |
int |
getHeight() |
Object |
getPixels() |
int |
getStatus() |
int |
getWidth() |
boolean |
grabPixels()
Have our Image or ImageProducer start sending us pixels via our
ImageConsumer methods and wait for all pixels in the grab
rectangle to be delivered.
|
boolean |
grabPixels(long ms)
grabPixels's behavior depends on the value of
ms . |
void |
imageComplete(int status)
Our
ImageProducer calls this method to inform us
that a single frame or the entire image is complete. |
void |
setColorModel(ColorModel model)
Our ImageProducer will call
setColorModel to
indicate the model used by the majority of calls to
setPixels . |
void |
setDimensions(int width,
int height)
Our
ImageProducer calls this method to indicate the
size of the image being produced. |
void |
setHints(int flags)
Our
ImageProducer may call this method with a
bit mask of hints from any of RANDOMPIXELORDER ,
TOPDOWNLEFTRIGHT , COMPLETESCANLINES ,
SINGLEPASS , SINGLEFRAME . |
void |
setPixels(int x,
int y,
int w,
int h,
ColorModel model,
byte[] pixels,
int offset,
int scansize)
Our ImageProducer calls setPixels to deliver a subset of its
pixels.
|
void |
setPixels(int x,
int y,
int w,
int h,
ColorModel model,
int[] pixels,
int offset,
int scansize)
Our ImageProducer calls setPixels to deliver a subset of its
pixels.
|
void |
setProperties(Hashtable<?,?> props)
Our
ImageProducer may call this method to send us a
list of its image's properties. |
void |
startGrabbing()
Start grabbing pixels.
|
int |
status() |
public PixelGrabber(Image img, int x, int y, int w, int h, int[] pix, int off, int scansize)
(x, y, w, h)
within the image. The data will be
stored in the provided pix
array, which must have
been initialized to a size of at least w * h
. The
data for a pixel (m, n) in the grab rectangle will be stored at
pix[(n - y) * scansize + (m - x) + off]
.img
- the Image from which to grab pixelsx
- the x coordinate, relative to img
's
top-left corner, of the grab rectangle's top-left pixely
- the y coordinate, relative to img
's
top-left corner, of the grab rectangle's top-left pixelw
- the width of the grab rectangle, in pixelsh
- the height of the grab rectangle, in pixelspix
- the array in which to store grabbed RGB pixel dataoff
- the offset into the pix
array at which to
start storing RGB datascansize
- a set of scansize
consecutive
elements in the pix
array represents one row of
pixels in the grab rectanglepublic PixelGrabber(ImageProducer ip, int x, int y, int w, int h, int[] pix, int off, int scansize)
(x, y, w, h)
within the image produced by
ip
. The data will be stored in the provided
pix
array, which must have been initialized to a
size of at least w * h
. The data for a pixel (m, n)
in the grab rectangle will be stored at
pix[(n - y) * scansize + (m - x) + off]
.ip
- the ImageProducer from which to grab pixels. This can
be null.x
- the x coordinate of the grab rectangle's top-left pixel,
specified relative to the top-left corner of the image produced
by ip
y
- the y coordinate of the grab rectangle's top-left pixel,
specified relative to the top-left corner of the image produced
by ip
w
- the width of the grab rectangle, in pixelsh
- the height of the grab rectangle, in pixelspix
- the array in which to store grabbed RGB pixel dataoff
- the offset into the pix
array at which to
start storing RGB datascansize
- a set of scansize
consecutive
elements in the pix
array represents one row of
pixels in the grab rectanglepublic PixelGrabber(Image img, int x, int y, int w, int h, boolean forceRGB)
(x, y, w, h)
within the image. The data will be
stored in an internal array which can be accessed by calling
getPixels
. The data for a pixel (m, n) in the grab
rectangle will be stored in the returned array at index
(n - y) * scansize + (m - x) + off
.
If forceRGB is false, then the returned data will be not be
converted to RGB from its format in img
.
If w
is negative, the width of the grab region will
be from x to the right edge of the image. Likewise, if
h
is negative, the height of the grab region will be
from y to the bottom edge of the image.img
- the Image from which to grab pixelsx
- the x coordinate, relative to img
's
top-left corner, of the grab rectangle's top-left pixely
- the y coordinate, relative to img
's
top-left corner, of the grab rectangle's top-left pixelw
- the width of the grab rectangle, in pixelsh
- the height of the grab rectangle, in pixelsforceRGB
- true to force conversion of the rectangular
region's pixel data to RGBpublic void startGrabbing()
public void abortGrabbing()
public boolean grabPixels() throws InterruptedException
InterruptedException
- if interrupted by another thread.public boolean grabPixels(long ms) throws InterruptedException
ms
.
If ms < 0, return true if all pixels from the source image have
been delivered, false otherwise. Do not wait.
If ms >= 0 then we request that our Image or ImageProducer start
delivering pixels to us via our ImageConsumer methods.
If ms > 0, wait at most ms
milliseconds for
delivery of all pixels within the grab rectangle.
If ms == 0, wait until all pixels have been delivered.InterruptedException
- if this thread is interrupted while
we are waiting for pixels to be deliveredpublic int getStatus()
public int getWidth()
public int getHeight()
public Object getPixels()
public ColorModel getColorModel()
public void setDimensions(int width, int height)
ImageProducer
calls this method to indicate the
size of the image being produced.
setDimensions is an ImageConsumer method. None of PixelGrabber's
ImageConsumer methods should be called by code that instantiates
a PixelGrabber. They are only made public so they can be called
by the PixelGrabber's ImageProducer.setDimensions
in interface ImageConsumer
width
- the width of the imageheight
- the height of the imagepublic void setProperties(Hashtable<?,?> props)
ImageProducer
may call this method to send us a
list of its image's properties.
setProperties is an ImageConsumer method. None of PixelGrabber's
ImageConsumer methods should be called by code that instantiates
a PixelGrabber. They are only made public so they can be called
by the PixelGrabber's ImageProducer.setProperties
in interface ImageConsumer
props
- a list of properties associated with the image being
producedpublic void setColorModel(ColorModel model)
setColorModel
to
indicate the model used by the majority of calls to
setPixels
. Each call to setPixels
could however indicate a different ColorModel
.
setColorModel is an ImageConsumer method. None of PixelGrabber's
ImageConsumer methods should be called by code that instantiates
a PixelGrabber. They are only made public so they can be called
by the PixelGrabber's ImageProducer.setColorModel
in interface ImageConsumer
model
- the color model to be used most often by setPixelsColorModel
public void setHints(int flags)
ImageProducer
may call this method with a
bit mask of hints from any of RANDOMPIXELORDER
,
TOPDOWNLEFTRIGHT
, COMPLETESCANLINES
,
SINGLEPASS
, SINGLEFRAME
.
setHints is an ImageConsumer method. None of PixelGrabber's
ImageConsumer methods should be called by code that instantiates
a PixelGrabber. They are only made public so they can be called
by the PixelGrabber's ImageProducer.setHints
in interface ImageConsumer
flags
- a bit mask of hintspublic void setPixels(int x, int y, int w, int h, ColorModel model, byte[] pixels, int offset, int scansize)
setPixels
in interface ImageConsumer
x
- x coordinate of pixel blocky
- y coordinate of pixel blockw
- width of pixel blockh
- height of pixel blockmodel
- color model used to interpret pixel datapixels
- pixel block dataoffset
- offset into pixels arrayscansize
- width of one row in the pixel blockpublic void setPixels(int x, int y, int w, int h, ColorModel model, int[] pixels, int offset, int scansize)
setPixels
in interface ImageConsumer
x
- x coordinate of pixel blocky
- y coordinate of pixel blockw
- width of pixel blockh
- height of pixel blockmodel
- color model used to interpret pixel datapixels
- pixel block dataoffset
- offset into pixels arrayscansize
- width of one row in the pixel blockpublic void imageComplete(int status)
ImageProducer
calls this method to inform us
that a single frame or the entire image is complete. The method
is also used to inform us of an error in loading or producing the
image.imageComplete
in interface ImageConsumer
status
- the status of image production, represented by a
bitwise OR of ImageConsumer flagspublic int status()