Android的图片缩小和preserving EXIF​​数据(定位,旋转等) [英] Android Image Resizing and Preserving EXIF data (Orientation, Rotation, etc)

查看:215
本文介绍了Android的图片缩小和preserving EXIF​​数据(定位,旋转等)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果你的Andr​​oid应用程序使用设备摄像头进行拍照,然后调整其大小(这是非常,非常普遍减少对上传的大小),你可能没有意识到,这个调整操作的的EXIF元数据。

If your Android app uses the device camera to take a picture and then resizes it (this is very, very common to reduce the size for upload), you might not realize that this resize operation strips the exif metadata.

这可能导致问题,特别是如果有问题的设备依赖于取向标记以正确直立显示图像。

This can cause problems, especially if the device in question relies on the 'Orientation' tag to properly show the image upright.

不同的Andr​​oid设备处理的相机/图像旋转以不同的方式 - 我信赖的醇'的Nexus One似乎永远旋转图像后立即拍摄,因此该文件的本地内容始终'正直'看。然而,其他设备(尤其是三星手机在我的测试),这样做的没有的旋转图像文件的内容 - 相反,他们设置了EXIF'定位'的标签。每当图像后显示,相关图像code应检测定位标签的presence并适当旋转图像。但是,如果你做任何位图处理的图像上,并保存到一个新的文件,所有的EXIF数据的丢失。

Different Android devices handle camera/image rotation in different ways - my trusty ol' Nexus One seems to always rotate the image immediately post capture, so the file's native contents are always 'upright' when viewed. However other devices (especially Samsung phones in my testing), do not rotate the contents of the image file - rather, they set the exif 'Orientation' tag. Whenever the image is displayed later, the relevant image code should detect the presence of the Orientation 'tag' and rotate the image appropriately. But if you have done any bitmap processing on the image and saved it to a new file, all of that exif data is lost.

在除了定位数据,也可能会失去其他有价值的元数据,如品牌/型号等。

In addition to Orientation data, you might also lose other valuable metadata such as make/model, etc.

这混淆了我几个星期(当手机图片库中显示,但后来我的服务器坏方向,并且没有明显的元数据到达的形象出现直立)。我将这种自我问题在这里帮助别人。本博客文章是非常有帮助的:

This confused me for a few weeks (image appears upright when displayed in phone gallery, but then arrives on my server with bad orientation and no apparent metadata). I'm adding this self-question here to help others. This blog post was very helpful:

<一个href="http://vikaskanani.word$p$pss.com/2011/07/17/android-re-size-image-without-loosing-exif-information/">http://vikaskanani.word$p$pss.com/2011/07/17/android-re-size-image-without-loosing-exif-information/

推荐答案

正如其他人所指出的,必须从原始图像复制的EXIF数据到最终调整后的图像。该Sanselan的Andr​​oid库通常是最适合这个。根据Android操作系统的版本,ExifInterface有时候会损坏EXIF数据。此外,ExifInterface还处理有限数量的Exif标签 - 即只有标记,它知道。 Sanselan在另一方面将保留所有EXIF标签和标记说明。

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.

下面是一个博客贴子,展示了如何使用Sanselan复制图像数据: <一href="http://bricolsoftconsulting.com/copying-exif-metadata-using-sanselan/">http://bricolsoftconsulting.com/copying-exif-metadata-using-sanselan/

Here is a blog post that shows how to use Sanselan for copying image data: http://bricolsoftconsulting.com/copying-exif-metadata-using-sanselan/

顺便说一句,在Android上我也倾向于旋转图像并取出方向的EXIF标签。例如,一个的Nexus S与Android 4.03,相机被设置在EXIF元数据的方向标记,但web视图被忽略的信息,并错误地显示图像。可悲的是,旋转实际图像数据,并移除EXIF方向标签是让每一个程序可以正确显示图像的唯一方法。

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的图片缩小和preserving EXIF​​数据(定位,旋转等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆