ExifInterface不会更新exif标记

sia*_*mii 6 android exif image

我正在尝试使用ExifInterface更改exif标签.我使用setAttribute()并调用saveAttributes().标签暂时保存,然后下一次旧值仍然存在且尚未更新................

例:

ExifInterface exifInterface = new ExifInterface(filePath);

String o1 = exifInterface.readAttribute(TAG_ORIENTATION); //o1 is "0"

exifInterface.setAttribute(TAG_ORIENTATION, "90");
exifInterface.saveAttributes();

String o2 = exifInterface.readAttribute(TAG_ORIENTATION); //o2 is "90"

// relaunch app, read attribute for same photo

String o3 = exifInterface.readAttribute(TAG_ORIENTATION); //o3 is "0" again, sould be "90"
Run Code Online (Sandbox Code Playgroud)

ete*_*nay 8

以防万一有人在寻找纯粹的Android解决方案:原始代码是正确的,但TAG_ORIENTATION属性值必须是1到8之间的值,如本页所述.

您必须使用readAttribute()方法调用来抑制该行,ExifInterface类中不存在此方法.exifInterface.getAttribute(ExifInterface.TAG_ORIENTATION, defaultValue)如果要在修改前后读取值,请将其替换.


小智 1

你应该使用类似的东西

exifInterface.setAttribute(TAG_ORIENTATION, ""+ExifInterface.ORIENTATION_ROTATE_90);
Run Code Online (Sandbox Code Playgroud)

反而

  • 我更喜欢永恒的解决方案。恕我直言,为这样一个简单的案例引入一个库是多余的。 (2认同)