Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get resolution of Image in Android / Java

Tags:

android

How can I find the resolution of any image in Android?

like image 736
CoDe Avatar asked May 23 '11 15:05

CoDe


2 Answers

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;
like image 98
Harish_N Avatar answered Nov 10 '22 21:11

Harish_N


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();
like image 45
George Avatar answered Nov 10 '22 21:11

George