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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.