Loading

读取图片旋转角度并转正

有的手机拍出来的照片是被旋转过得,此时,需要先旋转回正常的角度,再进行处理

读取图片旋转角度

public static int readPictureDegree(String path) {
    int degree = 0;
    try {
        ExifInterface exifInterface = new ExifInterface(path);
        int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
        LogW.out("readPictureDegree : orientation = " + orientation);
        if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
            degree = 90;
        } else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
            degree = 180;
        } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
            degree = 270;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return degree;
}

旋转图片

public static Bitmap rotateBitmap(int angle, Bitmap bitmap) {
    Matrix matrix = new Matrix();
    matrix.postRotate(angle);
    Bitmap rotation = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(),
            matrix, true);
    return rotation;
}

 

posted @ 2017-01-02 16:48  辉灬  阅读(1966)  评论(0编辑  收藏  举报