我想更新.jpg&的元数据(如标签,评论等......) .tif文件使用JAVA 任何人都可以帮助我......
注意:我尝试使用以下代码,但是当我使用Windows资源管理器查找文件的属性时,标题的值不会更新
public static void changeExifMetadata(File jpegImageFile, File dst)
throws IOException, ImageReadException, ImageWriteException {
OutputStream os = null;
try
{
TiffOutputSet outputSet = null;
IImageMetadata metadata = Sanselan.getMetadata(jpegImageFile);
JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
if (null != jpegMetadata)
{
TiffImageMetadata exif = jpegMetadata.getExif();
if (null != exif)
{
outputSet = exif.getOutputSet();
}else {}
}
if (null == outputSet)
outputSet = new TiffOutputSet();
{
final TiffOutputDirectory exifDir = outputSet .getOrCreateExifDirectory();
byte[] rawBytes = "KasperAuthor".getBytes("UTF-16LE");
byte[] nullTerminatedBytes = new byte[rawBytes.length + 2];
exifDir.removeField(ExifTagConstants.EXIF_TAG_XPTITLE);
TiffOutputField authorField = new TiffOutputField(ExifTagConstants.EXIF_TAG_XPTITLE, ExifTagConstants.EXIF_TAG_XPTITLE.dataTypes[0], nullTerminatedBytes.length, nullTerminatedBytes);
exifDir.add(authorField);
}
} finally
{
if (os != null)
try
{
os.close();
} catch (IOException e)
{
}
}
}
提前感谢....