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

前端 未结 10 2130
深忆病人
深忆病人 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:52

    private void getDropboxIMGSize(Uri uri){
       BitmapFactory.Options options = new BitmapFactory.Options();
       options.inJustDecodeBounds = true;
       BitmapFactory.decodeFile(new File(uri.getPath()).getAbsolutePath(), options);
       int imageHeight = options.outHeight;
       int imageWidth = options.outWidth;
     
    }
    

    no there is no way. You have to create a Bitmap object. if you use the inJustDecodeBounds flag the bitmap would not be loaded in memory. In fact BitmapFactory.decodeFile will return null. In my example uri is the phisical path to the image

提交回复
热议问题