Java读取图片EXIF信息

使用metadata-extractor-2.5.0-RC2.jar

 

package com;

import java.io.File;
import java.io.IOException;
import java.util.Collection;

import com.drew.imaging.jpeg.JpegMetadataReader;
import com.drew.imaging.jpeg.JpegProcessingException;
import com.drew.metadata.Directory;
import com.drew.metadata.Metadata;
import com.drew.metadata.Tag;
import com.drew.metadata.exif.ExifIFD0Directory;

public class Test {
	public static void main(String[] args) throws JpegProcessingException, IOException {
		File jpegFile = new File("D:\\mydoc\\canon\\20110313\\IMAG0023.jpg");
		Metadata metadata = JpegMetadataReader.readMetadata(jpegFile);
		Directory exif = metadata.getDirectory(ExifIFD0Directory.class);
		Collection<Tag> tags = exif.getTags();
		for(Tag tag : tags) {
			System.out.println(tag.getTagName() + ":" + tag);
		}
	}
}
 

 

运行结果:

Make:[Exif IFD0] Make - HTC
Model:[Exif IFD0] Model - HERO200
X Resolution:[Exif IFD0] X Resolution - 72 dots per inch
Y Resolution:[Exif IFD0] Y Resolution - 72 dots per inch
Resolution Unit:[Exif IFD0] Resolution Unit - Inch
YCbCr Positioning:[Exif IFD0] YCbCr Positioning - Center of pixel array

你可能感兴趣的:(java,图片,HTC,Exif)