Android 相机图像高度和宽度 return 不正确

Android Camera Image Height and Width return not true

在我的项目中,我想 select 将图像添加到图库中并将它们添加到回收视图中。但是当我选择垂直 phone 相机拍照时,它 return 反转高度和宽度。水平相机图像变为真实。顺便说一句,当有人从某个地方发送垂直图像时,它会 returns true。我看到日志,它说: D/height : 2322 , D/width: 4128 用于垂直图像。但恰恰相反。

这是我获取高度和宽度的代码:

public int drawableWidthFromPath(String path,int width)throws IOException{

        File imgFile = new File(path);
        int newWidth=0;

        if(imgFile.exists())
        {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            BitmapFactory.decodeFile(imgFile.getAbsolutePath(), options);
            int imageHeight = options.outHeight;
            int imageWidth = options.outWidth;


            Log.d("height", String.valueOf(imageHeight));
            Log.d("width", String.valueOf(imageWidth));


            newWidth = width*imageWidth/imageHeight;

        }


        return newWidth;
    }

此代码适用于:水平外包图像、垂直外包图像、水平相机图像,但不适用于垂直相机图像。顺便说一句,我试试

Bitmap x = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
x.getHeight();
x.getWidth();

但结果是 same.Here 是关于我所做的一些 ss:

我查看了 Twitter 照片选择器,它显示的图片完全真实。我的问题在哪里。谢谢

这是解决方案:

        switch(orientation) {

            case ExifInterface.ORIENTATION_ROTATE_90:
                selectedBitmap =rotateImage(selectedBitmap, 90);
                break;

            case ExifInterface.ORIENTATION_ROTATE_180:
                selectedBitmap =  rotateImage(selectedBitmap, 180);
                break;

            case ExifInterface.ORIENTATION_ROTATE_270:
                selectedBitmap =  rotateImage(selectedBitmap, 270);
                break;

            case ExifInterface.ORIENTATION_NORMAL:
                selectedBitmap =  rotateImage(selectedBitmap, 0);

            default:
                break;
        }