Java Reference
In-Depth Information
ImageViewer 1.0: the first complete version
We shall now work on creating the first complete version—one that can really accomplish the
main task: display some images.
Image-processing classes
On the way to the solution, we shall investigate one more interim version: imageviewer0-4 . Its
class structure is shown in Figure 11.5.
Figure 11.5
The class structure
of the image
viewer application
As you can see, we have added three new classes: OFImage , ImagePanel , and ImageFileManager .
OFImage is a class to represent an image that we want to display and manipulate. ImageFileManager
is a helper class that provides static methods to read an image file (in JPEG or PNG format) from disk
and return it in OFImage format and then save the OFImage back to disk. ImagePanel is a custom
Swing component to show the image in our GUI.
We shall briefly discuss the most important aspects of each of these classes in some more detail.
We shall not, however, explain them completely—that is left as an investigation for the curious
The OFImage class is our own custom format for representing an image in memory. You can
think of an OFImage as a two-dimensional array of pixels. Each of the pixels can have a color.
We use the standard class Color (from package java.awt ) to represent each pixel's color.
(Have a look at the documentation of class Color as well; we shall need it later.)
OFImage is implemented as a subclass of the Java standard class BufferedImage (from pack-
age java.awt.image ). BufferedImage gives us most of the functionality we want (it also
represents an image as a two-dimensional array), but it does not have methods to set or get a
pixel using a Color object (it uses different formats for this, which we do not want to use). So
we made our own subclass that adds these two methods.
For this project, we can treat OFImage like a library class; you will not need to modify this
Search WWH ::

Custom Search