gpt4 book ai didi

Android ExifInterface saveAttributes() 不覆盖以前的数据?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:15:18 34 4
gpt4 key购买 nike

我正在尝试将经纬度和其他数据写入自定义相机应用程序中 jpeg 的 Exif header 。通常,android 会自动使用光圈、ISO、快门速度等数据填充 header 。但是,当我手动添加创建一个 ExifInterface 实例时,使用 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();
}

谢谢

最佳答案

根据我看到的文档,这是不应该发生的。 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

它清楚地表明它正在复制所有数据,包括您所说的正在消失的东西。您能否发布您正在测试的内容。如果您使用的是 Android Studio,您可以尝试文件 -> 使缓存无效/重新启动 -> 无效并重新启动。

或者,我在这里找到了有关丢失数据的类似问题的答案: https://stackoverflow.com/a/13784057/3585278

As others have indicated, you must copy the EXIF data from the original image to the final resized image. The Sanselan Android library is typically best for this. Depending on Android OS version, the ExifInterface sometimes corrupts the EXIF data. In addition, the ExifInterface also handles a limited number of Exif tags -- namely only the tags that it "knows" about. Sanselan on the other hand will keep all EXIF tags and marker notes. Here is a blog post that shows how to use Sanselan for copying image data: http://bricolsoftconsulting.com/copying-exif-metadata-using-sanselan/ BTW, on Android I also tend to rotate the images and remove the Orientation EXIF tag. For example, on a Nexus S with Android 4.03, the camera was setting an orientation tag in the EXIF metadata, but the webview was ignoring that info and displaying the image incorrectly. Sadly, rotating the actual image data and removing the EXIF orientation tag is the only way to get every program to display images correctly.

希望对您有所帮助。

关于Android ExifInterface saveAttributes() 不覆盖以前的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25533330/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com