三星等手机拍照选取图片,图片反转的问题

来源:互联网 发布:房产数据哪个好 编辑:程序博客网 时间:2024/03/29 17:13
 /**
     * 得到 图片旋转 的角度
     * @param filepath
     * @return
     */
    private int getExifOrientation(String filepath) {
        int degree = 0;
        ExifInterface exif = null;
        try {
            exif = new ExifInterface(filepath);
        } catch (IOException ex) {
            Log.e("test", "cannot read exif", ex);
        }
        if (exif != null) {
            int orientation = exif.getAttributeInt(
                    ExifInterface.TAG_ORIENTATION, -1);
            if (orientation != -1) {
                switch (orientation) {
                    case ExifInterface.ORIENTATION_ROTATE_90:
                        degree = 90;
                        break;
                    case ExifInterface.ORIENTATION_ROTATE_180:
                        degree = 180;
                        break;
                    case ExifInterface.ORIENTATION_ROTATE_270:
                        degree = 270;
                        break;
                }
            }
        }
        return degree;
    }

int angle= getExifOrientation(picUri);
if(angle!=0){  //如果照片出现了 旋转 那么 就更改旋转度数
                    Matrix matrix = new Matrix();
                    matrix.postRotate(angle);
                    photoViewBitmap = Bitmap.createBitmap(photoViewBitmap,
                    0, 0, photoViewBitmap.getWidth(), photoViewBitmap.getHeight(), matrix, true);
                }
0 0