I would like to get a bitmap's dimensions in Android without reading the entire file.
I tried using the recommended inJustDecodeBounds
and a custom InputStream
that logged the read()
s. Unfortunately based on this, the Android BitmapFactory
appears to read a large amount of bytes.
Similar to: Java/ImageIO getting image dimensions without reading the entire file? for Android, without using ImageIO.
You are right to use inJustDecodeBounds. Set it to true and make sure to include Options in decode. This just reads the image size.
There is no need to read a stream. Just specify the path in the decode.
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(<pathName>, options);
int imageHeight = options.outHeight;
int imageWidth = options.outWidth;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With