CONTENTS | PREV | NEXT Java 2D API


5.3 Manipulating an Offscreen Buffer

The BufferedImage class allows you to directly manipulate the pixels in an image. This class supports fine-grain control over an image by allowing you to specify the image's ColorModel, image data, and data layout. By supplying storage space for the image data or access the existing storage data, you can manipulate the contents of an image directly.

A BufferedImage object can contain an alpha channel, just like any other image. In situations like the one illustrated in Figure 5-4, a 1-bit deep alpha channel is sufficient to distinguish the painted areas from the unpainted areas. The mask allows the image to blend with graphics that have already been painted (in this case, a shaded rectangle). In other situations, you might want a deeper alpha channel so you can manipulate the level of transparency in the image. You can control the alpha characteristics of a BufferedImage object by selecting an alpha channel of the appropriate depth, manipulating the data in the alpha channel, and changing the compositing operation in the Graphics2D object used to draw the BufferedImage.

An image's ColorModel specifies the color space of the data in an image's Raster and how the data is mapped to color and alpha components. The Raster defines the data and data layout within the image. With the information encapsulated by the Raster and ColorSpace objects, you can directly access and manipulate the pixels in an image.

The ColorModel, and ColorSpace classes are important whenever you need to know about pixel layouts; for example, when implementing new Composite objects or using BufferedImage objects.



CONTENTS | PREV | NEXT
Copyright © 1997-1998 Sun Microsystems, Inc. All Rights Reserved.