O'Reilly logo

Java 2D Graphics by Jonathan Knudsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

11.1. BufferedImage

The java.awt.image.BufferedImage class is the centerpiece of the 2D API's new image capabilities. As a subclass of java.awt.Image, you can pass a BufferedImage to all of the drawImage() methods in Graphics and Graphics2D. What's so great about BufferedImage? You can access the data for the image directly, a task that was awkward previously. In this section, I'll give a quick overview of all the classes that make up a BufferedImage. Then I'll talk briefly about how you can use BufferedImage directly without worrying about what's inside it. In the remainder of this chapter, I'll burrow deeper and deeper into BufferedImage.

11.1.1. Inside BufferedImage

Remember, an image is a rectangular array of colored pixels. That's all it is. As we discuss the innards of BufferedImage, it may sound a lot more complicated. It will help to keep the simple picture in your mind.

Figure 11.1 shows what's inside a BufferedImage. I'll explain the relationships between all the pieces in this section. In the rest of this chapter, I'll explain each class — ColorModel, Raster, SampleModel, and DataBuffer — in detail.

Figure 11.1. BufferedImage from top to bottom

Every BufferedImage consists of a raster and a color model. The image data itself resides in the raster, while the color model knows how to interpret the data as color.

The raster contains the data that determines each pixel's ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required