Exif数据最大的问题!没有为android中的图像返回正确的值

Exif数据最大的问题!没有为android中的图像返回正确的值,android,image,exif,Android,Image,Exif,大家好。我正在检查android默认摄像头拍摄的图片在图库中的方向。现在我们来看一个可怕和愤怒的完整问题。对于90度逆时针旋转,该死的exif返回方向旋转\u旋转\u 90。好吧,让我们假设它是好的。但问题是顺时针旋转90度该死的exif返回相同的等级!所以这两张图片是混合的。例如,我有两张图片,一张是逆时针90度拍摄的,另一张是顺时针90度拍摄的,但它们的两个exif值都是ORIENTATION\u ROTATE\u 90,所以每当我看到这个标签时,我只会旋转90度,一张图片旋转正确,但另一张

大家好。我正在检查android默认摄像头拍摄的图片在图库中的方向。现在我们来看一个可怕和愤怒的完整问题。对于90度逆时针旋转,该死的exif返回
方向旋转\u旋转\u 90
。好吧,让我们假设它是好的。但问题是顺时针旋转90度该死的exif返回相同的等级!所以这两张图片是混合的。例如,我有两张图片,一张是逆时针90度拍摄的,另一张是顺时针90度拍摄的,但它们的两个exif值都是
ORIENTATION\u ROTATE\u 90
,所以每当我看到这个标签时,我只会旋转90度,一张图片旋转正确,但另一张当然不正确,因为它必须以负值旋转,比如-90..,所以请告诉我该怎么做?这是我获取exif数据的代码

 public static int getRotationFromExif(String path) {
    try {
        ExifInterface exifInterface = new ExifInterface(path);
        int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);

        Log.d("dadada",orientation+"");
        if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
            return 180;
        } else if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
            return 90;
        } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
            return 270;
        } else if (orientation == ExifInterface.ORIENTATION_NORMAL) {
            return Rotation.ROTATION_NORMAL;
        } else if (orientation == ExifInterface.ORIENTATION_UNDEFINED) {
            return Rotation.ROTATION_UNDEFINED;
        } else {
            return 0;
        }

    } catch (Exception e) {
        return 0;
    }
}

这将是无缝的痛苦,因为客户端已经让我死了,因为在应用程序的库列表视图中图像旋转不正确…请帮助并告诉我这是否可能获得正确的信息,是否有任何库通常会告诉方向或至少相应地旋转位图?

如果您有图像的路径和位图,则可以使用以下方法使图像相应地旋转:

public Bitmap checkRotation(String filePath, Bitmap scaledBitmap) {
        ExifInterface exif;
        try {
            exif = new ExifInterface(filePath);

            int orientation = exif.getAttributeInt(
                    ExifInterface.TAG_ORIENTATION, 0);
            Log.d("EXIF", "Exif: " + orientation);
            Matrix matrix = new Matrix();
            if (orientation == 6) {
                matrix.postRotate(90);
                Log.d("EXIF", "Exif: " + orientation);
            } else if (orientation == 3) {
                matrix.postRotate(180);
                Log.d("EXIF", "Exif: " + orientation);
            } else if (orientation == 8) {
                matrix.postRotate(270);
                Log.d("EXIF", "Exif: " + orientation);
            }
            scaledBitmap = Bitmap.createBitmap(scaledBitmap, 0, 0,
                    scaledBitmap.getWidth(), scaledBitmap.getHeight(), matrix,
                    true);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return scaledBitmap;
    }

问题是,对于图像的逆时针旋转和图像的顺时针旋转,EXIF返回相同的值!所以我不能区别他们!因此,一个图像向左旋转,另一个图像正确旋转。我必须得到它返回的值是逆时针还是顺时针,这样我才能知道我应该旋转90度还是-90度,这是我的问题!检索位图后,上述代码将缩小、旋转并在图像视图中显示图像。
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && data != null) {
        Uri uri = data.getData();
        String[] projection = {MediaStore.Images.Media.DATA};
        Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
        cursor.moveToFirst();

        int columnIndex = cursor.getColumnIndex(projection[0]);
        String picturePath = cursor.getString(columnIndex);
        cursor.close();

        try {
            ImageView imageView = (ImageView) findViewById(R.id.imgView);
            Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
            int nh = (int) (bitmap.getHeight() * (1024.0 / bitmap.getWidth()));
            Bitmap scaled = Bitmap.createScaledBitmap(bitmap, 1024, nh, true);
            imageView.setImageBitmap(scaled);

            ExifInterface exif = new ExifInterface(picturePath);
            int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
            Log.d("EXIF", "Exif: " + orientation);
            Matrix matrix = new Matrix();
            if (orientation == 6) {
                matrix.postRotate(90);
            }
            else if (orientation == 3) {
                matrix.postRotate(180);
            }
            else if (orientation == 8) {
                matrix.postRotate(270);
            }
            scaled = Bitmap.createBitmap(scaled, 0, 0, scaled.getWidth(), scaled.getHeight(), matrix, true); // rotating bitmap
            imageView.setImageBitmap(scaled);

           } catch (IOException e) {
            e.printStackTrace();
        }
    }
}