Site logo, www.grelf.net
 
 

Reading & writing images in Java

 

Java's image reading and writing capabilities used to be very limited but since version 1.4 a new package has improved things enormously: javax.imageio (see Sun API documentation).

This package uses plug-ins for different image formats. The basic package reads and writes JPEG, PNG, BMP and GIF but JAR files are available to read other formats - importantly for us, including TIFF. The TIFF software is available from Sun under Java Advanced Imaging (JAI) as Image-I/O Tools.

At a simple level there is a simple static method, Imageio.read (java.io.File), which returns a java.awt.BufferedImage. However, there is more to be read from image files than simply the image. There may be metadata and there may be more than one image in the file - typically there will be a thumbnail image as well as the main one.

The imageio package defines a data structure, type IIOImage, which is able to hold all the images and metadata read from a file. This is used in the Im class in GRIP.

Another package called jrawio, from Tidal Wave, conforms to the JAI specification and enables RAW files in the formats of the major camera makers to be read. The JAR file for this is also provided with GRIP so that such files can be processed.

Next page