我正在使用 commons io 成像库将 xmp 元数据添加到 JPEG 文件。这就是我的做法:
String xmpXml = "<dc:decription>some sample desc123</dc:description>";
JpegXmpRewriter rewriter = new JpegXmpRewriter();
rewriter.updateXmpXml(is,os, xmpXml);
在上面的文件上运行exiftool
会显示从上面创建的 xmp 数据:
$ exiftool 167_sample.jpg | grep "Description"
Description : some sample desc123
但是,使用元数据提取器我无法Description
从上面读取标签:
Metadata metadata = com.drew.imaging.ImageMetadataReader.readMetadata(file.inputStream)
for (XmpDirectory xmpDirectory : metadata.getDirectoriesOfType(XmpDirectory.class)) {
XMPMeta xmpMeta = xmpDirectory.getXMPMeta();
XMPIterator itr = xmpMeta.iterator();
while (itr.hasNext()) {
XMPPropertyInfo property = (XMPPropertyInfo) itr.next();
System.out.println(property.getPath() + ": " + property.getValue());
}
}
更有趣的是,可以在创建xmp标签metadata-extractor
时Description
读取标签exiftool
$ exiftool -xmp-dc:description=Manuallyaddedthis 167_sample.jpg
Metadata metadata = com.drew.imaging.ImageMetadataReader.readMetadata(new File ("167_sample.jpg"))
for (XmpDirectory xmpDirectory : metadata.getDirectoriesOfType(XmpDirectory.class)) {
XMPMeta xmpMeta = xmpDirectory.getXMPMeta();
XMPIterator itr = xmpMeta.iterator();
while (itr.hasNext()) {
XMPPropertyInfo property = (XMPPropertyInfo) itr.next();
System.out.println(property.getPath() + ": " + property.getValue());
}
}