ExifInterface 不更新 exif 标签

发布于 2024-10-20 11:47:24 字数 572 浏览 3 评论 0原文

我正在尝试使用 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"

I'm trying to change exif tags with ExifInterface. I use setAttribute() and call saveAttributes(). The tag is saved temporarily, then next time the old value is still there and hasn't been updated................

Example:

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"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

╰つ倒转 2024-10-27 11:47:24

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

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

Just in case someone is looking for a pure android solution: original code is correct, but value of TAG_ORIENTATION attribute must be a value between 1 and 8, as explained in this page.

You must suppress the line with the call to readAttribute() method, this method doesn't exist in the ExifInterface class. Replace it with exifInterface.getAttribute(ExifInterface.TAG_ORIENTATION, defaultValue) if you want to read the value before and after the modification.

触ぅ动初心 2024-10-27 11:47:24

另请确保您的应用程序具有 WRITE_EXTERNAL_STORAGE 权限

Also make sure your app has the WRITE_EXTERNAL_STORAGE permission

百变从容 2024-10-27 11:47:24

你应该使用类似的

exifInterface.setAttribute(TAG_ORIENTATION, ""+ExifInterface.ORIENTATION_ROTATE_90);

东西

You should use something like

exifInterface.setAttribute(TAG_ORIENTATION, ""+ExifInterface.ORIENTATION_ROTATE_90);

instead

可是我不能没有你 2024-10-27 11:47:24

试试这个:

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));

Try this:

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文