get orientation of image from MediaStore.Images.Media.DATA

后端 未结 3 443
庸人自扰
庸人自扰 2021-01-06 09:37

i have MediaStore.Images.Media.DATA uri for an image how I can get MediaStore.Images.ImageColumns.ORIENTATION using that uri ? I am getting a NullPointerException.

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-06 10:12

    Use this method to get the Orientation

    public static int getExifOrientation(String filepath) {// YOUR MEDIA PATH AS STRING
            int degree = 0;
            ExifInterface exif = null;
            try {
                exif = new ExifInterface(filepath);
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            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;
        }
    

提交回复
热议问题