スキップしてメイン コンテンツに移動

Java: Read Exif Metadata Using metadata-extractor

In this post, I will show you the code snippet for extracting jpeg image exif metadata using metadata-extractor.

Code

package com.dukesoftware.image;

import com.drew.imaging.ImageMetadataReader;
import com.drew.imaging.ImageProcessingException;
import com.drew.metadata.Directory;
import com.drew.metadata.Metadata;
import com.drew.metadata.Tag;
import java.io.File;
import java.io.IOException;

public class MetaDataExtractor {

    public static void main(String[] args) throws IOException {
        printMetaData(new File("c:/temp/metadata_eample.jpg"));
    }

    private static void printMetaData(File file) throws IOException {
        try {
            Metadata drewmetadata = ImageMetadataReader.readMetadata(file);
            for (Directory directory : drewmetadata.getDirectories()) {
                System.out.println("==="+directory.getClass().getName()+"===");
                for (Tag tag : directory.getTags()) {
                    System.out.println(tag.getTagName()+ ": " + tag.getDescription());
                }
                System.out.println();
            }
        } catch (ImageProcessingException ipx) {
            
        }
    }

}

Example Result

I will show you the example execution result of the above code.
The test image is below.


The code output following result.

===com.drew.metadata.jpeg.JpegDirectory===
Compression Type: Baseline
Data Precision: 8 bits
Image Height: 1440 pixels
Image Width: 1440 pixels
Number of Components: 3
Component 1: Y component: Quantization table 0, Sampling factors 1 horiz/1 vert
Component 2: Cb component: Quantization table 1, Sampling factors 1 horiz/1 vert
Component 3: Cr component: Quantization table 1, Sampling factors 1 horiz/1 vert

===com.drew.metadata.jfif.JfifDirectory===
Version: 1.1
Resolution Units: inch
X Resolution: 96 dots
Y Resolution: 96 dots

===com.drew.metadata.exif.ExifSubIFDDirectory===
Exif Version: 2.20
Exif Image Width: 1440 pixels
Exif Image Height: 1440 pixels
Unique Image ID: 199e785efd74401dff564baa559c2f25
Unknown tag (0xea1c): [2060 bytes]

===com.drew.metadata.exif.ExifIFD0Directory===
Image Description: MetaData Example
Software: Picasa
Windows XP Title: MetaData Example
Windows XP Comment: Test Comments
Unknown tag (0xea1c): [2060 bytes]

===com.drew.metadata.exif.ExifThumbnailDirectory===
Thumbnail Compression: JPEG (old-style)
X Resolution: 72 dots per inch
Y Resolution: 72 dots per inch
Resolution Unit: Inch
Thumbnail Offset: 4488 bytes
Thumbnail Length: 6780 bytes

===com.drew.metadata.xmp.XmpDirectory===

===com.drew.metadata.photoshop.PhotoshopDirectory===
IPTC-NAA Record: 44 bytes binary data
Caption Digest: -100 14 -68 -116 -35 -121 -127 99 83 83 32 44 42 -84 14 25

===com.drew.metadata.iptc.IptcDirectory===
Enveloped Record Version: 

コメント