欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Java读取图片EXIF信息 博客分类: 技术 JavaEXIF图片HTC 

程序员文章站 2024-02-14 19:27:58
...

使用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