miui 10.2.2 或以上的小米手机上照片旋转问题及解决

问题描述

  • 在miui10.2.2 或以上的小米手机上出现的问题:调用手机相册选取使用手机拍摄的照片时,对照片进行压缩处理后图片会出现旋转。

解决方法:

  • 然后获取到旋转的角度,然后将图片旋转回来。

    1. 获取照片旋转角度,代码如下:
     public static int readPicDegree(String fileName) {
        int rotate = 0;
        try {
            ExifInterface exifInterface = new ExifInterface(fileName);
            int result = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                    ExifInterface.ORIENTATION_UNDEFINED);
            switch (result) {
                case ExifInterface.ORIENTATION_ROTATE_90:
                    rotate = 90;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_180:
                    rotate = 180;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_270:
                    rotate = 270;
                    break;
                default:
                    break;
            }
        } catch (Exception e) {
        }
        return rotate;
    }
    
    1. 对图片进行旋转处理,代码如下:
      public static Bitmap rotatePic(String fileName) {
        Bitmap bitmap = BitmapFactory.decodeFile(fileName);
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        Matrix matrix = new Matrix();
        matrix.postRotate(readPicDegree(fileName));
        bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
        return bitmap;
    }
    

    有些手机手机拍照之后也会发生旋转,也可以使用该方法进行处理

你可能感兴趣的:(miui 10.2.2 或以上的小米手机上照片旋转问题及解决)