Exif数据TAG_ORIENTATION始终为0

sga*_*man 24 camera android exif photo orientation

我需要知道图库中图像的方向(由相机拍摄).我最初的方法是使用适用于我的Droid 1的MediaStore.Images.Media.ORIENTATION.在HTC Thunderbolt上测试时,手机只能将0保存到该字段.

然后我开始阅读exif数据:

 ExifInterface exifReader = new ExifInterface(mFilePath);
 exifReader.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1);
Run Code Online (Sandbox Code Playgroud)

这也为每个图像返回0.任何人都有关于如何正确获取Android照片的方向的想法?

dba*_*ugh 28

这是我在我的活动中使用onActivityResult()的代码.返回的意图是选择图像/*类型的图像.对我来说效果很好!

Uri imageUri = intent.getData();
String[] orientationColumn = {MediaStore.Images.Media.ORIENTATION};
Cursor cur = managedQuery(imageUri, orientationColumn, null, null, null);
int orientation = -1;
if (cur != null && cur.moveToFirst()) {
    orientation = cur.getInt(cur.getColumnIndex(orientationColumn[0]));
}  
Matrix matrix = new Matrix();
matrix.postRotate(orientation);
Run Code Online (Sandbox Code Playgroud)

  • 谢谢 !请注意,现在不推荐使用managedQuery.您可以将其替换为"getApplicationContext().getContentResolver().query(...)". (4认同)

sga*_*man 5

我的解决方案

从exif数据中删除任何方向检查.我找不到一个准确的实例.

使用标准String[] orientationColumn = {MediaStore.Images.Media.ORIENTATION};来获得方向.

如果这是0使用decodeStream ...

if(o.outHeight > o.outWidth){
  //set orientation to portrait
}
Run Code Online (Sandbox Code Playgroud)

否则就是风景

  • 这对我不起作用,因为如果图像实际上处于不同的方向,高度,宽度会以某种方式正确切换. (2认同)