Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Exif数据标记方向始终为0_Android_Camera_Orientation_Photo_Exif - Fatal编程技术网

Android Exif数据标记方向始终为0

Android Exif数据标记方向始终为0,android,camera,orientation,photo,exif,Android,Camera,Orientation,Photo,Exif,我需要知道从画廊拍摄的图像的方向(由相机拍摄)。我最初的方法是使用MediaStore.Images.Media.ORIENTATION,它适用于我的Droid 1。在HTC Thunderbolt上测试时,该手机仅在该字段中保存0 然后我开始读取exif数据: ExifInterface exifReader = new ExifInterface(mFilePath); exifReader.getAttributeInt(ExifInterface.TAG_ORIENTATION, -

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

然后我开始读取exif数据:

 ExifInterface exifReader = new ExifInterface(mFilePath);
 exifReader.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1);
这也会为每个图像返回0。有人知道如何在android上正确获取照片的方向吗?

我的解决方案:

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

使用标准的
String[]orientationColumn={MediaStore.Images.Media.ORIENTATION}以获取方向

如果这是
0
使用 解码流


否则就是横向的

以下是我在活动中使用的activityresult()代码。返回的目的是拾取image/*类型的图像。很适合我

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);

这是我发现的一个bug,它与另一个android bug有关。。我在这里找到了一个合理的解决方案

这对我不起作用,因为如果图像实际处于不同的方向,高度、宽度都会正确地切换。只是更新我自己的问题,这就是我克服这个问题的方法;如果图像是正方形的,所以宽度和高度相同,但图像是反转的,我想翻转它怎么办?你能发布完整的解决方案吗?这种方法对我在画廊中获得图像的方向很有效。谢谢..!!:)谢谢请注意,managedQuery现在已不推荐使用。您可以将其替换为“getApplicationContext().getContentResolver().query(…)”。这是一个很好的解决方案,在ExiFinInterface不起作用的情况下对我有效。在牛轧糖上,从库中选择一个180方向的测试图像,返回0。我找到了另一个非常有效的解决方案!该链接发布了另一个链接,该链接发布了另一个链接。在这里,欺骗是一种犯罪。
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);