Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get bitmap width and height without loading to memory

Tags:

android

bitmap

Im a newbie in android, So i would like to know is there any way to get the dimensions of a Bitmap without loading the bitmap into memory.??

like image 752
Renjith Avatar asked Jul 27 '12 04:07

Renjith


1 Answers

You can set the BitmapFactory.Options with inJustDecodeBounds to get the image width and height without loading the bitmap pixel in memory

BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
bitmapOptions.inJustDecodeBounds = true;
BitmapFactory.decodeStream(inputStream, null, bitmapOptions);
int imageWidth = bitmapOptions.outWidth;
int imageHeight = bitmapOptions.outHeight;
inputStream.close();

For more details:

public boolean inJustDecodeBounds

Since: API Level 1 If set to true, the decoder will return null (no bitmap), but the out... fields will still be set, allowing the caller to query the bitmap without having to allocate the memory for its pixels.

http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html#inJustDecodeBounds

like image 176
Hanon Avatar answered Oct 18 '22 01:10

Hanon