I'm trying to write lat-long and other data to the Exif header of a jpeg in my custom camera app. Typically android automatically populates the header with data such as aperture, ISO, shutter speed etc. However, when I manually add create an ExifInterface
instance, set the GPS location with SetAttributes()
, and call SaveAttributes()
; all of the other camera data dissapears.
我想写坐标和其他数据的Exif头一个jpeg定制相机应用。通常安卓自动填充头与孔径等数据,ISO,快门速度等。然而,当我手动添加创建一个ExifInterface实例,设置GPS定位与SetAttributes(),并调用SaveAttributes();所有其他的相机数据都消失了。
Is this supposed to happen? How can I simply add a tag without overwriting everything else?
这应该发生吗?如何在不覆盖其他所有内容的情况下添加标记?
I saw an example elsewhere of creating two ExifInterfaces, an old(from the picture) and a new, and copying every populated value from the old to the new along with any other data. This however, is annoying and lengthy. I would like to find a better solution.
我在其他地方看到了创建两个存在面的示例,一个旧的(从图片中)和一个新的,并将所有填充的值从旧值复制到新值以及其他任何数据。然而,这是恼人的和冗长的。我想找到更好的解决办法。
Here is my code:
这是我的代码:
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();
}
Thanks
谢谢
1 个解决方案
#1
0
From the documentation I've seen this this is not supposed to happen. http://developer.android.com/reference/android/media/ExifInterface.html
从我看到的文件来看,这是不应该发生的。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
It clearly says that it's copying ALL the data, including the things that you say is vanishing. Could you maybe post what you are testing it on. If you are on Android Studio you could try File -> Invalidate Caches / Restart -> Invalidate and Restart.
它清楚地表明它正在复制所有的数据,包括你所说的正在消失的东西。你能把你正在测试的东西贴上去吗?如果您在Android Studio上,您可以尝试File -> Invalidate cache / Restart -> Invalidate和Restart。
Alternatively I found an answer to a similar question about losing the data here: https://*.com/a/13784057/3585278
或者,我找到了一个关于丢失数据的类似问题的答案:https://*.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.
正如其他人所指出的,您必须将EXIF数据从原始映像复制到最终调整大小的映像。Sanselan Android库通常是最好的。根据Android OS版本的不同,EXIF数据有时会被存在者窃取。此外,ExifInterface还处理有限数量的Exif标记,即只有它“知道”的标记。另一方面,Sanselan将保留所有EXIF标记和标记注释。这里有一篇博客文章展示了如何使用Sanselan复制图像数据:http://bricolsoftconsulting.com/copying-exif-metadata- usada -sanselan/ BTW,在Android I上,我也倾向于旋转图像并删除方向EXIF标签。例如,在搭载Android 4.03的Nexus S上,摄像头在EXIF元数据中设置了一个方向标签,但webview忽略了这个信息,并且不正确地显示图像。遗憾的是,旋转实际的图像数据并删除EXIF方向标签是使每个程序正确显示图像的唯一方法。
I hope this helps.
我希望这可以帮助。
#1
0
From the documentation I've seen this this is not supposed to happen. http://developer.android.com/reference/android/media/ExifInterface.html
从我看到的文件来看,这是不应该发生的。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
It clearly says that it's copying ALL the data, including the things that you say is vanishing. Could you maybe post what you are testing it on. If you are on Android Studio you could try File -> Invalidate Caches / Restart -> Invalidate and Restart.
它清楚地表明它正在复制所有的数据,包括你所说的正在消失的东西。你能把你正在测试的东西贴上去吗?如果您在Android Studio上,您可以尝试File -> Invalidate cache / Restart -> Invalidate和Restart。
Alternatively I found an answer to a similar question about losing the data here: https://*.com/a/13784057/3585278
或者,我找到了一个关于丢失数据的类似问题的答案:https://*.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.
正如其他人所指出的,您必须将EXIF数据从原始映像复制到最终调整大小的映像。Sanselan Android库通常是最好的。根据Android OS版本的不同,EXIF数据有时会被存在者窃取。此外,ExifInterface还处理有限数量的Exif标记,即只有它“知道”的标记。另一方面,Sanselan将保留所有EXIF标记和标记注释。这里有一篇博客文章展示了如何使用Sanselan复制图像数据:http://bricolsoftconsulting.com/copying-exif-metadata- usada -sanselan/ BTW,在Android I上,我也倾向于旋转图像并删除方向EXIF标签。例如,在搭载Android 4.03的Nexus S上,摄像头在EXIF元数据中设置了一个方向标签,但webview忽略了这个信息,并且不正确地显示图像。遗憾的是,旋转实际的图像数据并删除EXIF方向标签是使每个程序正确显示图像的唯一方法。
I hope this helps.
我希望这可以帮助。