我使用commons成像库将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());
}
}更有趣的是,当metadata-extractor 用于创建xmp标记时,exiftool可以读取Description标记。
$ 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());
}
}发布于 2016-10-27 21:24:31
元数据提取器为您附加到此问题的图像(第二,“自动粘附标签”)生成一个错误:
错误:处理XMP数据错误: XML解析失败
进一步看,XMP XML似乎只包含以下内容:
<dc:description>some sample description</dc:description>在您发布的代码的第一行中,很清楚原因。
这不是一个有效的XMP文档。Adobe的XMPCore库不接受它。
您可能希望使用XMPCore库来生成有效的XMP文档。或者,添加相关的父标记。
https://stackoverflow.com/questions/40275722
复制相似问题