如何在Android 10中获取图像的方向信息? [英] How to get an image's orientation information in android 10?

查看:72
本文介绍了如何在Android 10中获取图像的方向信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自android 10起,在访问媒体文件方面进行了一些更改.阅读完文档 https://developer.android.com/training/data-存储/共享/媒体我已经能够将媒体内容加载到位图中,但是我没有获得方向信息.我知道对图像的位置信息有一些限制,但是这些exif限制也会影响方向信息吗?如果还有其他方法可以获取图像的方向信息,请告诉我.下面给出了正在使用的代码(该代码始终返回0-未定义的值).谢谢.

Since android 10 there is some changes in accessing media files. After going through documentation https://developer.android.com/training/data-storage/shared/media i have been able to load the media content in to a bitmap, but i didn't get the orientation information. I know there is some restriction to the location information of the image, but does these exif restrictions also effect orientation information? If there is any other way to get an image's orientation information, please let me know. The code am using is given below (which is always returning 0 - Value for undefined). Thank you.

ContentResolver resolver = getApplicationContext().getContentResolver();
try (InputStream stream = resolver.openInputStream(selectedFileUri)) {
 loadedBitmap = BitmapFactory.decodeStream(stream);
 ExifInterface exif = new ExifInterface(stream);
 orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
}

推荐答案

BitmapFactory.decodeStream 消耗了整个流并关闭了它.

BitmapFactory.decodeStream consumed the whole stream and closed it.

在尝试读取exif之前,您应该先打开一个新流.

You should open a new stream first before trying to read the exif.

这篇关于如何在Android 10中获取图像的方向信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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