can i get image file width and height from uri in android?

前端 未结 10 2111
深忆病人
深忆病人 2020-12-08 01:58

i can getting the image width through MediaStore.Images.Media normally

but i need to getting the image width and height from image which selected from d

10条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-08 02:55

    The accepted answer returns with me a 0 of width/height, by replacing uri.getPath() with uri.getLastPathSegment(), it returns the correct dimensions

    public static int[] getImageDimension(Uri uri){
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(new File(uri.getLastPathSegment()).getAbsolutePath(), options);
        return new int[]{options.outWidth, options.outHeight};
    }
    

提交回复
热议问题