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
ただし、metadata-extractorDescriptionを使用すると、上からタグを読み取ることができません。
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());
}
}