Brief Tour of sun.awt.image
The classes in sun.awt.image
do the behind-the-scenes work for rendering an image from a file or across the network. This information is purely for the curious; you should never have to work with these classes yourself.
Image
- The
Image
class in this package represents a concreteImage
instance. It contains the basis for theImage
class that is actually used on the run-time platform, which exists in the package for the specific environment. For instance, thesun.awt.win32
package includes theW32Image
( Java 1.0), thesun.awt.windows
package includesWImage
( Java 1.1), while thesun.awt.motif
package includes theX11Image
, and thesun.awt.macos
package includes theMacImage
. ImageRepresentation
- The
ImageRepresentation
is theImageConsumer
that watches the creation of the image and notifies theImageObserver
when it is time to update the display. It plays an important part in the overall control of theImage
production process. - Image sources
- A Java image can come from three different sources: memory (through
createImage()
), local disk, or the network (throughgetImage()
).OffScreenImageSource
implementsImageProducer
for a single framed image in memory. When anImage
created from anOffScreenImageSource
is drawn withdrawImage()
, theImageObserver
parameter can benull
since all the image information is already in memory and there is no need for periodic updating as more is retrieved from disk. You can get the graphics context ofOffScreenImageSource
images and use the context to draw on the image area. This is how double buffering works.InputStreamImageSource
implementsImageProducer
for an image that comes from disk or across the network. When anImage
created from anInputStreamImageSource
is drawn withdrawImage()
, theImageObserver
parameter should be the component being drawn on (usuallythis
) since the image information will be loaded periodically with the help of theImageObserver
interface). This class determines how to decode the image type and initializes theImageDecoder
to one ofGifImageDecoder
,JPEGImageDecoder
, orXbmImageDecoder
, although that can be overridden by a subclass. It can use aContentHandler
to work with unknown image types.FileImageSource
is a subclass ofInputStreamImageSource
for images that come from the filesystem. It uses the filename to determine the type of image to decode and checks the security manager to ensure that access is allowed.URLImageSource
is a subclass ofInputStreamImageSource
for images that are specified by a URL.ByteArrayImageSource
( Java 1.1 only) is a subclass ofInputStreamImageSource
for images that are created by callingToolkit.createImage(byte[])
.
- Image decoders
- An
ImageDecoder
is utilized to convert the image source to an image object. If there is no decoder for an image type, it can be read in with the help of aContentHandler
or your own class that implementsImageProducer
, like thePPMImageDecoder
shown in Image Processing.GifImageDecoder
reads in an image file in the GIF format.JPEGImageDecoder
reads in an image file in the JPEG format.XbmImageDecoder
reads in an image file in the XBM format. Although XBM support is not required by the language specification, support is provided with Netscape Navigator, Internet Explorer, HotJava, and the Java Developer's Kit from Sun.
ImageFetcher
- The
ImageFetcher
class fetches the actual image from its source. This class creates a separate daemon thread to fetch each image. The thread is run at a higher priority than the default but not at the maximum priority.