[Apache Sanselan] Retrieving Image Metadata using Sanselan
Apache Sanselan is a pure Java library for reading and Writing Image formats. It has recently graduated from Incubator and is now a proud member of Apache commons proper.
In this article we shall see how to get Image metadata using Apache Sanselan.
Let’s see how the code looks
public static void main(String[] args) { String imageFile = args[0]; try { // Metadata details IImageMetadata meta = Sanselan.getMetadata(new File(imageFile)); System.out.println("--- Image Metadata ----"); System.out.println(meta); } catch (ImageReadException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
Most of the work is done in single line ?
getMetadata() API returns the IImageMetadata details. The toString() method of actual instance class of IImageMetadata prints the image information in a formatted fashion. The instance depends upon the format of the image.
Running the program on one the images shipped with Sanselan source produced this output
--- Image Metadata ----
Exif metadata:
Root:
Image Description: '’'
Make: 'Oregon Scientific'
Model: 'DS6639'
Orientation: 1
XResolution: 72
YResolution: 72
Resolution Unit: 2
Software: 'Adobe Photoshop 7.0'
Modify Date: '2008:07:13 21:05:34'
YCbCr Positioning: 2
Exif Offset: 228
Exif:
Exposure Time: 10/10266 (0.001)
FNumber: 28/10 (2.8)
Exposure Program: 2
ISO: 55
Exif Version: 48, 50, 50, 48
Date Time Original: '2003:10:20 09:01:29'
Create Date: '2003:10:20 09:01:29'
Components Configuration: 1, 2, 3, 0
Compressed Bits Per Pixel: 2
Brightness Value: 9
Exposure Compensation: 0
Max Aperture Value: 3
Metering Mode: 1
Light Source: 0
Flash: 0
Focal Length: 864/100 (8.64)
Subject Location: 27556, 57533, 60147, 20319
Flashpix Version: 48, 49, 48, 48
Color Space: 1
Exif Image Width: 300
Exif Image Length: 225
File Source: 3
Scene Type: 1
Custom Rendered: 0
Exposure Mode: 0
White Balance: 1
Digital Zoom Ratio: 1
Focal Length In 3 5mm Format: 42
Scene Capture Type: 0
Gain Control: 0
Contrast: 0
Saturation: 0
Sharpness: 0
Sub: (jpegImageData)
Compression: 6
XResolution: 72
YResolution: 72
Resolution Unit: 2
Jpg From Raw Start: 838
Jpg From Raw Length: 6258
Photoshop (IPTC) metadata:
Caption/Abstract: ?
