Java Reference
In-Depth Information
Another approach to image creation is to build them directly from pixel arrays.
We discuss this approach in the image-processing sections later in this chapter.
11.6 Saving images
Although the core Java packages always provided for reading JPEG files, it wasn't
until Java 1.4 that the core language allowed for saving images to disk files in JPEG
format. Sun previously provided the package com.sun.image.codec.jpeg
for writing to JPEG files but it belonged to the category of optional packages,
which meant that it was only available for a limited number of platforms instead
of all J2SE-compatible systems.
With Java 1.4 came the javax.imageio package and sub-packages that
allow for both reading and writing of JPEG and PNG images. With Java 5.0 came
BMP/WBMP image reading and writing. GIF files can be read but not saved. The
GIF encoder involves the patented LZW compression algorithm so GIF encoding
was not included in the standard Java packages. GIF encoders can be obtained
from third party sources. See the Web Course Chapter 11 for links to several
independent image handling packages that provide for saving images in these
and other formats.
Java image I/O includes the javax.imageio.* packages. The javax.
imageio.ImageIO class provides a number of static methods for image reading
and writing with several encoding formats. For example,
...
BufferedImage bi = myImageAnalysis ();
File file = new File ( " c: \ images \ anImage.jpg " );
ImageIO.write (bi, " jpeg " , file);
The second parameter of write() is a string that corresponds to a supported
format. Some platforms may allow for other formats besides the standard ones.
A list of supported writer formats can be obtained with
String[] format - names = ImageIO.getWriterFormatNames ();
The javax.imageio classes also provide for more sophisticated image han-
dling such as creating plug-ins for reading and writing custom image formats.
See the Image I/O API Guide and the Java API Specifications for more about
these classes [4,5].
11.7 Image processing
By the term image processing we refer both to manipulating images and to
extracting information from them. With the tools available in Java we can manip-
ulate images with several types of high level filters such as affine transforms and
Search WWH ::




Custom Search