安卓:将GPSTimeStamp放入jpg文件的EXIF标签

19
我在尝试通过Android在JPG的exif标签中设置“GPSTimeStamp”。然而,有关此操作的文档非常缺乏:
http://developer.android.com/reference/android/media/ExifInterface.html#TAG_GPS_TIMESTAMP 类型为字符串,常量值为:“GPSTimeStamp”。但确切的格式是什么呢?

参考这里: https://ExifTool.org/TagNames/GPS.html
GPSTimeStamp: rational64u[3] (写入时,如果存在日期,则将其删除,并且如果时间包括时区,则将其调整为UTC)

我需要一个长整数值和一个3维数组?我不确定应该放什么。我通过location.gettime()方法获取了“自1970年1月1日以来的UTC毫秒数”的UTC时间。
http://developer.android.com/reference/android/location/Location.html#getTime%28%29
如果我将长整数值作为字符串写入时间戳并通过Linux上的“exif”检查exif标签,则会出现错误“预期分母”。所有以hh:mm:ss或其他格式的实验都失败了。我有点迷失方向。
1个回答

3
< p >对于样本时间14:22:32GPSTimeStamp属性的正确格式为:

"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/

即使过了几年,你仍然可以得到答案。太棒了,谢谢。这个应用程序早已不复存在,但这可能会帮助其他人。 :) - Redfox
Invalid value for GPSTimeStamp : 13/1,43/1,49/1 - user924
该值应编码为有理数数组(字节数组编码整数对)。它不应该是ASCII字符串属性。 - John Gietzen

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接