Android 判断imageview角度并旋转

/**
 * 读取照片exif信息中的旋转角度
 *
 * @return角度 获取从相册中选中图片的角度
 */
public static float readPictureDegree(String path) {
    int degree = 0;
    try {
        ExifInterface exifInterface = new ExifInterface(path);
        int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
        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;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return degree;
}

/**
 * 旋转图片,使图片保持正确的方向。
 */
   public static Bitmap rota(float degrees,Bitmap bitmap){
    Matrix matrix = new Matrix();
    matrix.setRotate(degrees, bitmap.getWidth() / 2, bitmap.getHeight() / 2);
    Bitmap bmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
    if (null != bitmap) {
        bitmap.recycle();
    }
    return bmp;
}

 

你可能感兴趣的:(Android,图片)