Java Reference
In-Depth Information
contrast-intense images in order to achieve the same visual quality. Some
compressed image formats are loss-free, i.e. the original image can be precisely
recovered.
The Java libraries support the following image formats. When loading such an
image it is automatically decompressed and can be displayed.
Graphics Interchange Format, file extension GIF. This format stores images in
256-bit colours, one byte per pixel. The pictures are compressed without loss of
information. It is often used for small icons or graphics on the Internet. Using
this format might cause legal problems, because the CompuServe company
holds patents for the compression method.
Joint Photographic Experts Group, file extensions JPG, JPEG. This format
uses a compression method in which image information is lost. For photos a
reduction to 20 per cent of the original image file size can be achieved while
still maintaining a good quality. JPEG is probably the most widely used format
to store larger photos or drawings.
Portable Network Graphic, file extension PNG. A newer image format with
growing importance. It uses a loss-free compression and might replace the GIF
format in the long run.
Most Internet browsers can render images in any of these three formats. In this
topic we shall mostly use PNG images; the examples work also when using JPEG or
GIF. Using compressed image formats is especially advisable if the pictures have
to be sent over a network: sending or loading times are drastically reduced.
Loading a large image into an application takes some time, even on a modern
computer. To save the user from waiting for the image to be displayed, images are
often loaded asynchronously . This means that a second process is started which
runs in parallel to the main program and loads the image. This way the main
program is not blocked and the user can go on working while the image is loaded.
If, however, the image has to be processed right away by the application then it
should be loaded synchronously and the main program has to wait until the image
is available.
15.2
Class ImageIcon
The Swing library provides class ImageIcon for pixel graphics. Although 'icon' is
mostly used for small images this class is well suited to handle large images and
supports the basic operations on images. For more elaborate manipulation, class
Image from the AWT library can be used. Some constructors and methods of class
ImageIcon are listed and described below:
ImageIcon()
ImageIcon(Image picture)
ImageIcon(String filename)
ImageIcon(URL webaddress)
Search WWH ::




Custom Search