Android图像调整大小并保留EXIF数据(方向,旋转等) [英] Android image resizing and preserving EXIF data (orientation, rotation, etc.)

查看:347
本文介绍了Android图像调整大小并保留EXIF数据(方向,旋转等)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您的Android应用使用设备相机拍摄照片然后调整大小(这是非常常见的做法,可以减小上传的大小),那么您可能没有意识到此调整大小操作条纹 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.

这可能会引起问题,特别是如果所涉及的设备依靠"Orientation"标签正确显示垂直图片.

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

不同的Android设备以不同的方式处理摄像头/图像旋转-我可信赖的旧Nexus One似乎总是在捕获后立即旋转图像,因此在查看文件时,文件的本机内容始终为竖直".

Different Android devices handle camera/image rotation in different ways - my trusty old Nexus One seems to always rotate the image immediately post capture, so the file's native contents are always 'upright' when viewed.

但是,其他设备(尤其是在我测试中的三星手机)不会旋转图像文件的内容-而是设置Exif'Orientation'标签.每当稍后显示图像时,相关的图像代码应检测到方向标签"的存在并适当旋转图像.但是,如果您对图像进行了任何位图处理并将其保存到新文件中,则所有该Exif数据都会丢失.

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:

Android重新调整图片大小,而不会丢失EXIF信息

推荐答案

正如其他人指出的那样,您必须将Exif数据从原始图像复制到最终调整大小的图像. Sanselan Android库通常最适合此功能.根据Android操作系统的版本,ExifInterface有时会破坏Exifdata.

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 Exifdata.

此外,ExifInterface还处理有限数量的Exif标记,即仅处理其知道"的标记.另一方面,Sanselan将保留所有Exiftag和标记注释.

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 Exiftags and marker notes.

这是一篇博客文章,展示了如何使用Sanselan复制图像数据:

Here is a blog post that shows how to use Sanselan for copying image data:

使用Sanselan复制Exif元数据

顺便说一句,在Android上,我也倾向于旋转图像并删除Orientation Exiftag.例如,在具有Android 4.03的Nexus S上,摄像头在Exifmetadata中设置了方向标签,但Web视图忽略了该信息并错误地显示了图像.可悲的是,旋转实际图像数据并删除Exiforientation标签是使每个程序正确显示图像的唯一方法.

BTW, on Android I also tend to rotate the images and remove the Orientation Exiftag. For example, on a Nexus S with Android 4.03, the camera was setting an orientation tag in the Exifmetadata, but the webview was ignoring that information and displaying the image incorrectly. Sadly, rotating the actual image data and removing the Exiforientation tag is the only way to get every program to display images correctly.

这篇关于Android图像调整大小并保留EXIF数据(方向,旋转等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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