Android:将GPSTimeStamp放入jpg EXIF标签中

问题描述 投票:16回答:1

我试图通过Android将“ GPSTimeStamp”设置为jpg的exif标签。该文档在这一方面非常稀缺:http://developer.android.com/reference/android/media/ExifInterface.html#TAG_GPS_TIMESTAMP类型是字符串。常数:“ GPSTimeStamp”。但是确切的格式是什么?

看这里:https://ExifTool.org/TagNames/GPS.htmlGPSTimeStamp: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或其他格式的实验都失败了。在这里有点迷路。

android tags exif gps-time
1个回答
1
投票

采样时间GPSTimeStamp14: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/

© www.soinside.com 2019 - 2024. All rights reserved.