問題描述
我已經研究并嘗試了許多選項來嘗試讓它工作,但不幸的是我沒有得到任何結果.
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 標簽的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!