如何用Java读取JPEG文件属性? [英] How to read JPEG file attributes with Java?
本文介绍了如何用Java读取JPEG文件属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从图像(jpg)中读取信息,其中包含数码相机中包含的额外
信息,如创建日期,焦点,闪存
关闭,...
如何我可以获得这些信息。
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.
我的第一个想法是。
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);
}
}
但getPropertyNames()返回null!
But the getPropertyNames() returns null!
推荐答案
另一个简单的选择是使用元数据提取器:
Another simple option is to use metadata-extractor:
Metadata metadata = ImageMetadataReader.readMetadata(imagePath);
迭代文件中的所有值:
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);
图书馆也适用于Maven用户。
The library is available for Maven users too.
(完全披露:我是这个图书馆的作者)
这篇关于如何用Java读取JPEG文件属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文