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

前端 未结 10 2110
深忆病人
深忆病人 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 03:00

    Blackbelt's answer is correct if you have a file uri. However, if you are using the new file providers as in the official camera tutorial, it won't work. This works for that case:

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeStream(
            getContext().getContentResolver().openInputStream(mPhotoUri),
            null,
            options);
    int imageHeight = options.outHeight;
    int imageWidth = options.outWidth;
    

提交回复
热议问题