2011-02-02 102 views
15

我試圖通過android將「GPSTimeStamp」設置爲jpg的exif標籤。這個文檔很少:
http://developer.android.com/reference/android/media/ExifInterface.html#TAG_GPS_TIMESTAMP 類型是字符串。常量值:「GPSTimeStamp」。但確切的格式是什麼?Android:將GPSTimeStamp轉換爲jpg EXIF標籤

看這裏: http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/GPS.html
GPSTimeStamp:rational64u [3](書寫時,日期如果存在剝離,並且時間調整爲UTC,如果它包括一個時區)

所以我需要一個長期價值一個3單元陣列?我不確定,應該輸入什麼。我已經獲得了「此修復的UTC時間,以1970年1月1日以來的毫秒爲單位」。通過location.gettime()。
http://developer.android.com/reference/android/location/Location.html#getTime%28%29
如果我將long值作爲字符串寫入Timestamp並在Linux上通過「exif」檢查exif標記,則會出現「預計分母」的錯誤。所有使用hh:mm:ss或其他格式的實驗都失敗了。在這裏有點失落。

回答

1
GPSTimeStamp屬性爲採樣時間 14:22:32

正確格式是

"14/1,22/1,32/1" 
分割的問題

您可以使用下面的代碼:

Location location = ...; // TODO - Set location properly. 
long locationTome = location.getTime(); 
ExifInterface imageExif = new ExifInterface("absolute_path_to_image"); 
Calendar calendar = Calendar.getInstance(); 

calendar.setTimeInMillis(locationTome); 
int hourOfDay = calendar.get(Calendar.HOUR_OF_DAY); 
int minutes = calendar.get(Calendar.MINUTE); 
int seconds = calendar.get(Calendar.SECOND); 

String exifGPSTimestamp = hourOfDay + "/1," + minutes + "/1," + seconds + "/1"; 

imageExif.setAttribute("GPSTimeStamp", exifGPSTimestamp); 
imageExif.saveAttributes(); 

它具有類似的格式爲GPSLatitudeGPSLongitude屬性。這種格式的有用解釋也可以在這裏找到:http://www.ridgesolutions.ie/index.php/2015/03/05/geotag-exif-gps-latitude-field-format/

+0

甚至幾年後,你仍然可以得到答案。太好了,謝謝。這個應用程序已經很長時間了,但這可能有助於其他人。 :) – Redfox 2015-04-13 09:23:01

1

在從Android上的Camera.java源代碼setGpsTimestamp有如下的描述和實施方法:

/** 
    * Sets GPS timestamp. This will be stored in JPEG EXIF header. 
    * 
    * @param timestamp GPS timestamp (UTC in seconds since January 1, 
    *     1970). 
    */ 
    public void setGpsTimestamp(long timestamp) { 
     set(KEY_GPS_TIMESTAMP, Long.toString(timestamp)); 
    } 

所以你修復以毫秒爲單位的UTC時間必須轉換成秒,所以它只是由1000