How can I find the resolution of any image in Android?
The efficient way to get size of an image stored in disk (for example to get the size of an image file selected by the user for uploading) is to use BitmapFactory.Options
and set inJustDecodeBounds
to true. By doing so you will get the size(Width and Height) of an image file without loading the entire image into memory. This will help when want to check the resolution of an image before uploading.
String pickedImagePath = "path/of/the/selected/file";
BitmapFactory.Options bitMapOption=new BitmapFactory.Options();
bitMapOption.inJustDecodeBounds=true;
BitmapFactory.decodeFile(pickedImagePath, bitMapOption);
int imageWidth=bitMapOption.outWidth;
int imageHeight=bitMapOption.outHeight;
If your image is on your res/drawable, you can use something like this:
Bitmap bmp = BitmapFactory.decodeResource(res, R.drawable.back);
bmp.getWidth(), bmp.getHeight();
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