Click here to Skip to main content
13,299,495 members (68,373 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 6 Jan 2011

Retrieve Exchangeable Image File Format Data using Apache Sanselan

, 6 Jan 2011
Rate this:
Please Sign up or sign in to vote.
How to retrieve exchangeable image file format data using Apache Sanselan

Exchangeable image file format (Exif) is a specification for the image file format used by digital cameras. The specification uses the existing JPEG, TIFF Rev. 6.0, and RIFF WAV file formats, with the addition of specific metadata tags. As we are now aware of what these things are, why not write a Small Java application to extract these data. But developing a full-fledged API is beyond the scope of this blog. So, I chose to use Sanselan from Apache Foundation. This Pure-Java library reads and writes a variety of image formats, including fast parsing of image info (size, color space, icc profile, etc.) and metadata. You can download it from Apache website at Using Sanselan, it is very easy to read Exif tags. I have written a small piece of code to get the basic information of an image. The steps required to perform are as follows:

Step 1

Download Sanselan JAR files from Apache website.

Step 2

Create a Java Project in your eclipse and Add Sanselan lib at your classpath.

Step 3

Write ExifReader class to read Exif tag information.

package blog.exif.util;
import java.util.Hashtable;
import org.apache.sanselan.ImageReadException;
import org.apache.sanselan.Sanselan;
import org.apache.sanselan.common.IImageMetadata;
import org.apache.sanselan.formats.jpeg.JpegImageMetadata;
import org.apache.sanselan.formats.tiff.TiffField;
import org.apache.sanselan.formats.tiff.constants.TiffConstants;
* @author Bikash
public class ExifReader {
public static Hashtable getMetadata(File file) throws ImageReadException, IOException {
  IImageMetadata metadata = Sanselan.getMetadata(file);
  Hashtable<String, String> exifInfomationTable = new Hashtable<String, String>();
  if (metadata instanceof JpegImageMetadata) {
    JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
    TiffField field = jpegMetadata
    exifInfomationTable.put(field.getTagName(), field.getValueDescription());
    field = jpegMetadata.findEXIFValue(TiffConstants.EXIF_TAG_MODEL);
    exifInfomationTable.put(field.getTagName(), field.getValueDescription());
    field = jpegMetadata.findEXIFValue(TiffConstants.EXIF_TAG_CREATE_DATE);
    exifInfomationTable.put(field.getTagName(), field.getValueDescription());
    field = jpegMetadata.findEXIFValue(TiffConstants.EXIF_TAG_FNUMBER);
    exifInfomationTable.put(field.getTagName(), field.getValueDescription());
    field = jpegMetadata.findEXIFValue(TiffConstants.EXIF_TAG_ISO);
    exifInfomationTable.put(field.getTagName(), field.getValueDescription());
    field = jpegMetadata.findEXIFValue(TiffConstants.EXIF_TAG_EXPOSURE_TIME);
    exifInfomationTable.put(field.getTagName(), field.getValueDescription());
    field = jpegMetadata.findEXIFValue(TiffConstants.EXIF_TAG_EXIF_IMAGE_WIDTH);
    exifInfomationTable.put(field.getTagName(), field.getValueDescription());
    field = jpegMetadata.findEXIFValue(TiffConstants.EXIF_TAG_EXIF_IMAGE_LENGTH);
    exifInfomationTable.put(field.getTagName(), field.getValueDescription());
  return exifInfomationTable;

Step 4

Create a Main class to validate the correctness of the information:

package blog.exif.main;
import java.util.Hashtable;
import org.apache.sanselan.ImageReadException;
import blog.exif.util.ExifReader;
* @author Bikash
public class Main {
  public static void main(String[] args) {
  File file = new File("D:\\Photos\\Kashmir\\DSC01945.JPG");
  try {
    Hashtable<String, String> exifInfomationTable = ExifReader.getMetadata(file);
    for(String key : exifInfomationTable.keySet())
      System.out.println(key + " : " + exifInfomationTable.get(key));
  } catch (ImageReadException e) {
  } catch (IOException e) {

Step 5

Execute the application to see the output.

Now, the power is in your hand. Feel free to add or change the values of TiffConstants to get more information. You can even develop your swing base GUI utility for more robust image metadata reader.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Bikash Shaw
Software Developer (Senior) Société Générale
India India

1. Extensive working experience in web and windows application development, database programming using Java and .Net technologies.

2. Good knowledge in SDLC and Processes like project planning, requirement gathering, development, test planning, release management and production support.

3. Good knowledge and working experience in following methodologies:
a. Agile Development Approach
b. Test Driven Development
c. Behavior Driven Development
d. Continuous Integration & Delivery Model.

4. Excellent communication & analytical skills, good team player, great mentoring capability.

5. Interaction with customer and team spread over different geographical area.

Technologies / Languages: J2SE 5/6, J2EE, .Net 2.0/3.5, C#, ASP.NET, AJAX, XHTML, CSS, JavaScript, jQuery, PL/SQL, Web Services (SOAP based), Winforms, Hibernate, Spring, GWT, XML, XSD, XPath, SAX, JAXB, JUnit, JBehave, Mockito, Selenium, StringTemplate, Log4J, Apache Commons API

Database: Oracle, SQL Server, MySQL, Sybase

Application Server: Tomcat, Sun Application Server, JBoss, GlassFish, Jetty, IIS

Development Environments: Eclipse, NetBeans, Visual Studio.

Designing Tools: Enterprise Architect, Microsoft Visio

Version Control: SVN, Perforce

Build Management: Hudson & JCruisemonitor, TeamCity

Bug Tracking Tools: HP Quality Center, Bugzilla, JIRA

1. Agile Test and Behavior Driven Development
2. Continuous Delivery Approach
2. Spring IOC and MVC
3. Web Services

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171207.1 | Last Updated 6 Jan 2011
Article Copyright 2011 by Bikash Shaw
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid