如下就是我读取出来的Exif信息。如何用Java实现将User Comment这条属性添加到Exif信息中
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
public static void main(String[] args) throws Exception {
//原文件
InputStream fip = new BufferedInputStream(new FileInputStream("D://nozip//2.jpg")); // No need to buffer
LLJTran llj = new LLJTran(fip);
try {
llj.read(LLJTran.READ_INFO, true);
} catch (LLJTranException e) {
e.printStackTrace();
}
Exif exif = (Exif) llj.getImageInfo();
/* Set some values directly to gps IFD */
Entry e;
// Set Latitude
e = new Entry(Exif.ASCII);
e.setValue(0, 'N');
exif.setTagValue(Exif.GPSLatitudeRef,-1, e, true);
//设置具体的精度
e = new Entry(Exif.RATIONAL);
e.setValue(0, new Rational(31, 1));
e.setValue(1, new Rational(21, 1));
e.setValue(2, new Rational(323, 1));
exif.setTagValue(Exif.GPSLatitude,-1, e, true);
// Set Longitude
e = new Entry(Exif.ASCII);
e.setValue(0, 'E');
exif.setTagValue(Exif.GPSLongitudeRef,-1, e, true);
//设置具体的纬度
e = new Entry(Exif.RATIONAL);
e.setValue(0, new Rational(120, 1));
e.setValue(1, new Rational(58, 1));
e.setValue(2, new Rational(531, 1));
exif.setTagValue(Exif.GPSLongitude,-1, e, true);
llj.refreshAppx(); // Recreate Marker Data for changes done
//改写后的文件,文件必须存在
OutputStream out = new BufferedOutputStream(new FileOutputStream("D://nozip//1.jpg"));
// Transfer remaining of image to output with new header.
llj.xferInfo(null, out, LLJTran.REPLACE, LLJTran.REPLACE);
fip.close();
out.close();
llj.freeMemory();
}