Class Exif

  extended by

public class Exif
extends java.lang.Object

An API for accessing EXIF encoded information in a JPEG file.

JPEG images are stored in a tagged format reminiscent of TIFF files. Each component of the image is identified with a tag number and a size. This allows applications that read JPEG files to skip over information that they don't understand.

Additional resources:

This class treats a byte array as a JPEG image and parses the tags searching for EXIF data. EXIF data is also tagged. Based on information provided by the caller, this class builds a hash of EXIF data and makes it available to the caller.

Most simple EXIF values are tagged with both their identity and their format. For example, ExposureTime (0x829A) is a rational number and this class can extract that value. However, some fields are of "unknown" format. If you decode one of these, you can add a special purpose decode for that field by associating the name of the decoder class with the field name. For example, my Nikon CoolPix 950 includes a MakerNote (0x927C) field that's tagged "unknown" format. Using information from TsuruZoh's page, I've built a decoder for that field and added it as an example.

In addition to the tagged data, JPEG images have five intrinisic properties: height, width, the compression algorithm used, the number of bits used to store each pixel value, and the number of color components. This class allows the caller to unify those intrinsic components with the tagged data.

In an effort to be flexible without requiring users to change the source, a fair bit of setup is needed to use this class.

The caller must:

  1. Construct an Exif object, exif = new Exif().
  2. Associate names with each of the tags of interest, exif.addTag(nnn, "name").
  3. Associate names with the intrinsic values:
  4. Finally, the caller may associate a decoder with specific fields: exif.addDecoder("name", "").

Having setup the exif object, it can be passed to JpegHeaders to be filled in when the JPEG file is parsed.

The caller must also explicitly set the intrinsic values since they do not come from the EXIF data.

After parsing the JPEG, call exif.getTags() to get back the has of name/value pairs.

See Also:
ExifData, TagDecoder, JpegHeaders

Constructor Summary
Method Summary
 void addBitsPerPixel(java.lang.String name)
 void addCompression(java.lang.String name)
 void addDecoder(java.lang.String name, java.lang.String className)
 void addHeight(java.lang.String name)
 void addNumberOfColorComponents(java.lang.String name)
 void addTag(int tag, java.lang.String tagName)
 void addWidth(java.lang.String name)
protected  void assignByte(java.lang.String tagName, int offset)
protected  void assignRational(java.lang.String tagName, int offset)
protected  void assignSByte(java.lang.String tagName, int offset)
protected  void assignSLong(java.lang.String tagName, int offset)
protected  void assignSShort(java.lang.String tagName, int offset)
protected  void assignString(java.lang.String tagName, int offset, int length)
protected  void assignULong(java.lang.String tagName, int offset)
protected  void assignUndefined(java.lang.String tagName, int offset, int length)
protected  void assignUShort(java.lang.String tagName, int offset)
 java.util.Hashtable getTags()
 void parseExif(byte[] exifData)
protected  void processExifDir(int dirStart, int offsetBase)
 void setBPP(int bitsPP)
 void setCompression(java.lang.String comp)
 void setHeight(int height)
 void setNumCC(int numCC)
 void setWidth(int width)
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public Exif()
Method Detail


public void parseExif(byte[] exifData)


public void setHeight(int height)


public void setWidth(int width)


public void setCompression(java.lang.String comp)


public void setBPP(int bitsPP)


public void setNumCC(int numCC)


public void addHeight(java.lang.String name)


public void addWidth(java.lang.String name)


public void addCompression(java.lang.String name)


public void addBitsPerPixel(java.lang.String name)


public void addNumberOfColorComponents(java.lang.String name)


public void addTag(int tag,
                   java.lang.String tagName)


public void addDecoder(java.lang.String name,
                       java.lang.String className)


public java.util.Hashtable getTags()


protected void processExifDir(int dirStart,
                              int offsetBase)


protected void assignUndefined(java.lang.String tagName,
                               int offset,
                               int length)


protected void assignString(java.lang.String tagName,
                            int offset,
                            int length)


protected void assignSByte(java.lang.String tagName,
                           int offset)


protected void assignByte(java.lang.String tagName,
                          int offset)


protected void assignUShort(java.lang.String tagName,
                            int offset)


protected void assignSShort(java.lang.String tagName,
                            int offset)


protected void assignULong(java.lang.String tagName,
                           int offset)


protected void assignSLong(java.lang.String tagName,
                           int offset)


protected void assignRational(java.lang.String tagName,
                              int offset)