Joh*_*nnB 10 android jpeg exif android-camera
我正在尝试将lat-long和其他数据写入我的自定义相机应用程序中的jpeg的Exif标头.通常,android会自动使用光圈,ISO,快门速度等数据填充标题.但是,当我手动添加创建ExifInterface实例时,请设置GPS位置SetAttributes(),然后调用SaveAttributes(); 所有其他相机数据消失.
这应该发生吗?如何在不覆盖其他所有内容的情况下添加标签?
我在其他地方看到了创建两个ExifInterfaces的示例,一个旧的(从图片中)和一个新的,并将每个填充的值从旧的复制到新的以及任何其他数据.然而,这是令人烦恼和冗长的.我想找到一个更好的解决方案.
这是我的代码:
try{
ExifInterface exif = new ExifInterface(pictureFile.getAbsolutePath());
exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, mGpsLocation.getLatDms());
exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, mGpsLocation.getLonDms());
exif.setAttribute(ExifInterface.TAG_GPS_ALTITUDE, mGpsLocation.getAltDms());
exif.saveAttributes();
} catch(IOException e){
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
谢谢
从我看到的文档中,这是不应该发生的。 http://developer.android.com/reference/android/media/ExifInterface.html
public void saveAttributes ()
Added in API level 5
Save the tag data into the JPEG file. This is expensive because it involves copying all the JPG data from one file to another and deleting the old file and renaming the other. It's best to use setAttribute(String, String) to set all attributes to write and make a single call rather than multiple calls for each attribute.
Throws
IOException
Run Code Online (Sandbox Code Playgroud)
它清楚地表明它正在复制所有数据,包括您所说的正在消失的数据。您可以发布您正在测试的内容吗?如果您使用的是 Android Studio,您可以尝试“文件”->“无效缓存/重新启动”->“无效并重新启动”。
另外,我在这里找到了有关丢失数据的类似问题的答案: /sf/answers/964884021/
正如其他人所指出的,您必须将 EXIF 数据从原始图像复制到最终调整大小的图像。Sanselan Android 库通常最适合此目的。根据 Android 操作系统版本,ExifInterface 有时会损坏 EXIF 数据。此外,ExifInterface 还处理有限数量的 Exif 标记——即仅处理它“知道”的标记。另一方面,Sanselan 将保留所有 EXIF 标签和标记注释。这是一篇博客文章,展示了如何使用 Sanselan 复制图像数据: http://bricolsoftconsulting.com/copying-exif-metadata-using-sanselan/ 顺便说一句,在 Android 上我也倾向于旋转图像并删除方向 EXIF标签。例如,在运行 Android 4.03 的 Nexus S 上,相机在 EXIF 元数据中设置方向标签,但 Web 视图忽略该信息并错误地显示图像。遗憾的是,旋转实际图像数据并删除 EXIF 方向标签是让每个程序正确显示图像的唯一方法。
我希望这有帮助。
| 归档时间: |
|
| 查看次数: |
1854 次 |
| 最近记录: |