Chapter 18. Working with Images and Other Media
Up to
this point, we’ve confined ourselves to working with the
high-level drawing commands of the Graphics2D
class, using images in a hands-off mode. In this section, we’ll
clear up some of the mystery surrounding images and see how they are
created and used. The classes in the
java.awt.image
package handle images and their
insides; Figure 18.1 shows the important
classes in this package.[47]

Figure 18-1. The java.awt.image package
First, we’ll return to our discussion of image observers and
see how we can get more control over image data as it’s
processed asynchronously by GUI components. Then we’ll open the
hood and have a look at the inside of a
BufferedImage. If you’re interested in
creating sophisticated graphics, such as rendered images or video
streams, this will teach you about the foundations of image
construction in Java.
Implementing an ImageObserver
The architects of Java realized that
images might take some time to load over a slow network. Image observers implement the
ImageObserver interface. They are effectively nosy
neighbors of images that watch as the image data arrives.
An image is simply a rectangle of pixels. A pixel has both a color and a transparency; the transparency specifies how pixels underneath the image show through. For a static image, such as a GIF or JPEG data file, the observer is notified when the entire ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access