我想更新.jpg&的元数据(如标签,评论等......) .tif文件使用JAVA 任何人都可以帮我举例......
我使用apache poi为docx文件做了同样的事情
OPCPackage opc = OPCPackage.open("metadata.docx");
PackageProperties pp = opc.getPackageProperties();
Nullable<String> foo = pp.getLastModifiedByProperty();
System.out.println(foo.hasValue()?foo.getValue():"empty");
//Set some properties
pp.setCreatorProperty("M Kazarian");
pp.setLastModifiedByProperty("M Kazarian " + System.currentTimeMillis());
pp.setModifiedProperty(new Nullable<Date>(new Date()));
pp.setTitleProperty("M Kazarian document");
注意:然后请提及我应该下载的jar和&amp;导入以更新元数据。
提前感谢....
答案 0 :(得分:0)
尝试使用commons imaging
Here是如何更新JPEG元数据的示例:
public void changeExifMetadata(final File jpegImageFile, final File dst)
throws IOException, ImageReadException, ImageWriteException {
OutputStream os = null;
boolean canThrow = false;
try {
TiffOutputSet outputSet = null;
final IImageMetadata metadata = Imaging.getMetadata(jpegImageFile);
final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
if (null != jpegMetadata) {
final TiffImageMetadata exif = jpegMetadata.getExif();
if (null != exif) {
outputSet = exif.getOutputSet();
}
}
if (null == outputSet) {
outputSet = new TiffOutputSet();
}
{
final TiffOutputDirectory exifDirectory = outputSet
.getOrCreateExifDirectory();
exifDirectory
.removeField(ExifTagConstants.EXIF_TAG_APERTURE_VALUE);
exifDirectory.add(ExifTagConstants.EXIF_TAG_APERTURE_VALUE,
RationalNumber.factoryMethod(3, 10));
}
{
final double longitude = -74.0;
final double latitude = 40 + 43 / 60.0;
outputSet.setGPSInDegrees(longitude, latitude);
}
os = new FileOutputStream(dst);
os = new BufferedOutputStream(os);
new ExifRewriter().updateExifMetadataLossless(jpegImageFile, os,
outputSet);
canThrow = true;
} finally {
IoUtils.closeQuietly(canThrow, os);
}
}
答案 1 :(得分:0)
javax.imageio.metadata包含与元数据相关的类。 IIOMetadata类对您有用。请尝试
write(IIOMetadata streamMetadata,IIOImage image,ImageWriteParam param)
ImageWriter类中的方法。