是否可以使BitmapFactory.decodeFile()尊重EXIF? [英] Is it possible to make BitmapFactory.decodeFile() respect EXIF?

查看:196
本文介绍了是否可以使BitmapFactory.decodeFile()尊重EXIF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的测试中, BitmapFactory.decodeFile()创建的位图不尊重EXIF标题。

In my tests, a Bitmap created by BitmapFactory.decodeFile() doesn't respect EXIF header.

例如,使用不会根据相机方向旋转实际像素数据的设备拍摄的肖像图像,而是将其存储在EXIF标题中,当我正在调用 Bitmap.getWidth() Bitmap.getHeight(),它们返回不正确的值(宽度的高度,反之亦然)。

For example, with portrait images taken by a devices that doesn't rotate actual pixel data depending on camera orientation but rather stores it in EXIF header, when I'm calling Bitmap.getWidth() and Bitmap.getHeight(), they return incorrect values (height for width and vice versa).

有没有办法让 BitmapFactory.decodeFile()尊重EXIF并产生正确的位图

Is there a way to make BitmapFactory.decodeFile() respect EXIF and produce a correct Bitmap?

如果没有,处理此问题的推荐模式是什么?

If not, what is the recommended pattern to handle this issue?

如果没有经验丰富的Android开发者的建议,我看到的唯一方法是预处理拍摄的图像(根据EXIF加载,旋转并保存)。但是除了巨大的处理开销之外,对于大型摄像机分辨率,这可能会导致 OutOfMemoryException (如果使用 BitmapFactory无法降低质量的情况.Options.inSampleSize 加载缩小图像)。

Without an advice from experienced Android devs, the only way I see is to pre-process taken images (load, rotate according to EXIF, and save). But apart from the huge processing overhead, this might cause OutOfMemoryExceptions for large camera resolutions (in cases when you can't reduce the quality by using BitmapFactory.Options.inSampleSize to load downscaled images).

推荐答案


是有没有办法使BitmapFactory.decodeFile()尊重EXIF并产生正确的位图?

Is there a way to make BitmapFactory.decodeFile() respect EXIF and produce a correct Bitmap?

不,抱歉。


处理此问题的推荐模式是什么?

what is the recommended pattern to handle this issue?

使用支持库的 ExifInterface 来确定所需的方向。然后,根据您对位图的使用,旋转视图(例如, ImageView )或旋转位图此示例项目说明了两种方法,但我使用一组单独的EXIF代码,因为我在该示例中使用的一些内容不受支持库的 ExifInterface 支持。

Use the support library's ExifInterface to determine the desired orientation. Then, depending upon your use of the Bitmap, either rotate the view (e.g., ImageView) or rotate the Bitmap. This sample project illustrates both approaches, though I use a separate set of EXIF code, as some things that I use in that sample are not supported by the support library's ExifInterface.

这篇关于是否可以使BitmapFactory.decodeFile()尊重EXIF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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