miui10.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;
    }
    

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

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值