无法在 Android 中使用 ExifInterface 设置 Date Taken/DateTime 标签 [英] Cant set Date Taken/DateTime tag using the ExifInterface in Android

查看:32
本文介绍了无法在 Android 中使用 ExifInterface 设置 Date Taken/DateTime 标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经研究并尝试了许多选项来尝试让它工作,但不幸的是我没有得到任何结果.

I've researched and tried numerous options to try and get this to work, but am not getting anywhere with this unfortunately.

我要做的是在 Android 应用程序中的 JPEG 的 Exif 数据中设置拍摄日期标签 (Tag_DateTime).我已经有工作代码来设置纬度和经度标签,但我一生都无法设置拍摄日期标签.

What I am trying to do is set the Date Taken tag (Tag_DateTime) in a JPEG's Exif data from within an Android app. I already have working code to set the Latitude and Longitute tags, but cannot for the life of me get the Date taken tag to set.

代码如下:

SimpleDateFormat fmt_Exif = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
try {
    ExifInterface exif = new ExifInterface(filePhoto.getPath());

    // Set and save the GPS and time data
    exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, strLat);
    exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, strLong);
    exif.setAttribute(ExifInterface.TAG_DATETIME, fmt_Exif.format(locLatestLocation.getTime()));
    exif.saveAttributes();

} catch (IOException e) {
    e.printStackTrace();
}

  • locLatestLocation - 用于获取时间的位置(以毫秒为单位).
  • fmt_Exif - SimpleDateFormat 用于将毫秒时间格式化为 TAG_DateTime Exif 标记的正确格式.
  • strLat &strLong - 以正确的格式填充到其他位置以设置纬度和经度标签.
  • 我在某处的帖子中读到该标签需要以毫秒格式编写,因此也尝试过,但无济于事.为了用实际存储的内容确认我的格式,我从具有 Date Taken 标签的 jpeg 文件中读取并输出了未格式化的标签,但输出的格式与我写入标签的格式完全相同,而且它仍然不工作.

    I read in a post somewhere that the tag needs to be written in the milliseconds format, so have tried this too to no avail. In order to confirm my formatting with what is actually stored, I read and outputted the unformatted tag from a jpeg file which has the Date Taken tag, but the output is in exactly the same format as what I am writing to the tag and its still not working.

    可能还值得一提的是,我已经研究了 Sanselan 类来执行此操作,并且由于复杂性和缺乏示例,我宁愿尝试让我现有的解决方案工作,然后再更改为完全不同的解决方案.

    It might also be worth mentioning that I have looking into the Sanselan class to do this, and due to the complexity and lack of examples would much rather try and get my existing solution working before changing to a completely different one.

    有没有人设法做到这一点,如果有,我做错了什么??

    Has anyone managed to do this and if so what am I doing wrong??

    推荐答案

    Android 的 ExifInterface 很烦人,会默默地丢弃它认为无效的任何数据.更糟糕的是,文档甚至没有提到有效值可能是什么.

    Android's ExifInterface, annoyingly, silently discards any data it deems to be invalid. Worse yet, the documentation doesn't even mention what valid values might be.

    我还发现,如果你指定了一个Android无法识别的EXIF属性(IE:它不是ExifInterface的TAG_常量之一),它也会完全忽略它,也会默默失败.

    I've also found that if you specify an EXIF attribute that Android can't figure out (IE: it's not one of ExifInterface's TAG_ constants), it will also completely ignore it, and also fail silently.

    这篇关于无法在 Android 中使用 ExifInterface 设置 Date Taken/DateTime 标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆