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

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

    Please use InputStream:

    public int[] getImageSize(Uri uri){
        try {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            InputStream input = this.getContentResolver().openInputStream(uri);
            BitmapFactory.decodeStream(input, null, options);  input.close();
            return new int[]{options.outWidth, options.outHeight};
        }
        catch (Exception e){}
        return new int[]{0,0};
    }
    

    It'll return in array form:

    int[]{ width , height }
    

提交回复
热议问题