11.3. Rasters

Image data is contained in a raster, represented by an instance of java.awt.image.Raster. Rasters themselves are composed of two pieces—a sample model and a data buffer. The data buffer contains the raw data, while the sample model describes how the data is organized.

The Raster class is useful for two reasons. First, it can retrieve image data by asking its sample model to pull the data out from the data buffer. Second, Raster contains many static factory methods that create commonly used Rasters.

Sidebar 2. What's a Raster?

In the old days of computers, screen devices came in two varieties: raster and vector. Both types had one or more electron guns that spewed electrons through a phosphorescent screen. The difference had to do with how the gun was aimed. A vector screen device kept track of a specific list of lines (vectors) that it would draw. You might have seen this type of device in arcade video games from the early 1980s, like Asteroids, Battlezone, and Tempest.

The other type of screen device, raster, is the familiar television-style device. The electron gun (or guns) sweep across horizontal lines (scanlines) of the screen in a left-to-right, top-to-bottom order, changing intensity to indicate different colors.

The difference between vector and raster devices is analogous to the difference between a pen plotter and a dot matrix or laser printer.

Vector screen devices have gone to the great output device in the sky, leaving raster devices as the only widespread ...

Get Java 2D Graphics 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.