Android:gpstimestampをjpg exifタグに入れます
質問
「gpstimestamp」をAndroid経由でJPGのEXIFタグに設定しようとしています。これにはドキュメントがかなり不足しています:
http://developer.android.com/reference/android/media/exifinterface.html#tag_gps_timestampタイプは文字列です。一定の値:「gpstimestamp」。しかし、正確な形式は何ですか?
ここを見てください:http://www.sno.phy.queensu.ca/~phil/exiftool/tagnames/gps.html
GPSTIMESTAMP:Rational64U [3](書くとき、存在する場合は日付が除去され、TimeZoneが含まれている場合はUTCに時間が調整されます)
それで、私は3セル配列に長い値が必要ですか?何を入れるべきかわかりません。「1970年1月1日以来、この修正のUTC時間」を取得しました。 location.getTime()経由。
http://developer.android.com/reference/android/location/location.html#gettime%28%29
長い値を文字列としてタイムスタンプに書き込み、Linux上の「exif」を介してExifタグを確認すると、エラー「分母が期待される」を取得します。 HH:MM:SS、またはその他の形式を使用したすべての実験は失敗しました。ここで少し迷子になっています。
解決
適切な形式 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();
同様の形式があります GPSLatitude
と GPSLongitude
属性。このような形式の有用な説明は、ここにも見つけることができます: http://www.ridgesolutions.ie/index.php/2015/05/geotag-exif-gps-latitude-field-format/