Grabbing Pixels

As we've seen, the AWT provides extensive support for filtering images. However, sometimes it is convenient to be able access the pixel data of an image without having to bother with implementing an image filter in order to access this data. do so. That is precisely the role of the PixelGrabber class. PixelGrabber is an implementation of the ImageConsumer interface that grabs a rectangular region of pixels within a given image.

PixelGrabber provides three constructors that take the following arguments:

(Image im, int x, int y, int w, int h, boolean forceRGB
(Image im, int x, int y, int w, int h, int[] buffer,
           int offset, int scansize)
(ImageProducer ip, int x, int y, int w, int h, int[] buffer,
           int offset, int scansize)

All ...

Get Graphic Java™ 1.2, Volume I: AWT, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.