Java Reference
In-Depth Information
model is the default while other models include the gray-scale model with only
one sample per pixel and index models where a data value holds an index into a
palette of a limited number of colors. For example, a sample model for a binary
black and white image packed as bits would send its zeros and ones to an index
color model that would in turn assign zero to black (RGB 0x000000) and one to
white (RGB 0xFFFFFF).
The BufferedImage is intended to handle the many different ways that
images can be encoded and stored. Except for specialized cases, you don't need
to deal directly with the details of the internal structure of the class. In Sec-
tion 11.8.4 we show how to create an ARGB image and a gray-scale image from
pixel data. Other examples are given in the Web Course Chapter 11.
11.3 Image loading
The Java AWT core language classes originally provided for loading and display
of images in GIF and JPEG encoding format. With Java 1.4 came access to PNG
encoding and with Java 5.0 came the bitmap formats BMP and WBMP.
We mentioned in Chapter 6 that an image does not actually begin loading when
an applet invokes the getImage() method. The loading begins only when the
program attempts to access the image such as by invoking drawImage() in the
graphics context or by invoking the getWidth() or getHeight() methods
of the Image class. Image loading typically requires a substantial amount of
bandwidth on the network so the Java designers sought to postpone the loading
of an image in case it was never needed.
Once the loading starts, it may require a substantial amount of time, especially
over a slow link. Other threads in the program can continue to run in parallel
while an internal thread takes care of the image loading. Java provides two ways
to monitor the loading to know when it has finished:
1. Implement the ImageObserver interface and provide the imageUpdate() method.
2. Use an instance of MediaTracker to load one or more images simultaneously.
Yo u can also use ImageIcon to load an image. This class holds an internal
MediaTracker to monitor the loading. Another image loading option is to use
the read() methods in the javax.imageio.ImageIO class. We discuss these
techniques below.
11.3.1 ImageObserver
When a program invokes the drawImage() method of the Graphics class, the
method returns before the image display has completed the loading and drawing
of the image. A separate thread takes over this job while your program can go on
Search WWH ::




Custom Search