I want to read information from an image (jpg) which has some extra information included from a digital camera like creation date, focus, flash on off, ... How can I get this information.
My first idea was.
BufferedImage image = ImageIO.read(filePicture);
if (image().getPropertyNames() != null) {
for (int j = 0; j < image().getPropertyNames().length; j++) {
String key = image().getPropertyNames()[j];
String value = (String) image().getProperty(key);
System.out.println(key + ": " + value);
}
}
But the getPropertyNames() returns null!
Java 2D supports loading these external image formats into its BufferedImage format using its Image I/O API which is in the javax. imageio package. Image I/O has built-in support for GIF, PNG, JPEG, BMP, and WBMP.
A typical JPEG file contains a lot more information than just the bytes required to store image data. A JPEG file also has a lot of metadata in each file containing auxiliary information about the image. On an average, this kind of metadata occupies 16% of size of the JPEG file.
In Java, we can use the javax. imageio. ImageIO class to read and write an image.
Another simple option is to use metadata-extractor:
Metadata metadata = ImageMetadataReader.readMetadata(imagePath);
To iterate all values in the file:
for (Directory directory : metadata.getDirectories()) {
for (Tag tag : directory.getTags()) {
System.out.println(tag);
}
}
You can also read specific values from specific directories:
// obtain the Exif SubIFD directory
ExifSubIFDDirectory directory
= metadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class);
// query the datetime tag's value
Date date = directory.getDate(ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL);
The library is available for Maven users too.
(Full disclosure: I am the author of this library)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With