Java 关于捕获图像旋转

Java 关于捕获图像旋转,java,android,Java,Android,在Moto设备中从相机拍摄图像后,图像设置为向左旋转90度。 我已经在谷歌上搜索了使用过的ExiFinInterface,但没有解决。将此代码添加到onActivityResult并传递图像路径 public void rotateCapturedImage(String imagePath) { try { Bitmap sourceBitmap = BitmapFactory.decodeFile(imagePath); sou

在Moto设备中从相机拍摄图像后,图像设置为向左旋转90度。
我已经在谷歌上搜索了使用过的ExiFinInterface,但没有解决。

将此代码添加到onActivityResult并传递图像路径

public void rotateCapturedImage(String imagePath) {
        try {
            Bitmap sourceBitmap = BitmapFactory.decodeFile(imagePath);
            sourceBitmap = getScaledBitmap(sourceBitmap, MediaPickerActivity.this);
            ExifInterface ei = new ExifInterface(imagePath);
            Bitmap bitmap = null;
            int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
//          Toast.makeText(mContext,"orientation "+orientation,Toast.LENGTH_SHORT).show();
            switch (orientation) {
                case ExifInterface.ORIENTATION_ROTATE_90:
                    bitmap = RotateBitmap(sourceBitmap, 90);
                    if (bitmap != null)
                        saveBitmap(bitmap, new File(imagePath));
                    break;
                case ExifInterface.ORIENTATION_ROTATE_180:
                    bitmap = RotateBitmap(sourceBitmap, 180);
                    if (bitmap != null)
                        saveBitmap(bitmap, new File(imagePath));
                    break;
                case ExifInterface.ORIENTATION_ROTATE_270:
                    bitmap = RotateBitmap(sourceBitmap, 270);
                    if (bitmap != null)
                        saveBitmap(bitmap, new File(imagePath));
                    break;

                default:
                    saveBitmap(sourceBitmap, new File(imagePath));
                    break;

            }
            sourceBitmap.recycle();
            if (bitmap != null)
                bitmap.recycle();

        } catch (IOException e) {
            e.printStackTrace();
        } catch (NullPointerException e) {
            // null value
        } catch (OutOfMemoryError e) {
            // null value
        }
    }

展示你尝试了什么,以及为什么没有成功。如果您不这样做,您的问题可能会作为您尝试但未展示的内容的副本关闭。请查看上面的链接代码的照片?真正地请通过编辑问题将代码添加为文本。