Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android bitmap image size

I am downloading images from web and i use Gallery widget to display the images.

If the downloaded image size is huge, my application crashes with the below log.

"E/GraphicsJNI( 3378): VM won't let us allocate 5591040 bytes"

I want to scale down the downloaded image size only when the image size is more to an extent that it will crash the app. I have written the code to scale down the image size but i am not sure how to find the bitmap size so i can decide on whether to scale or not

   BitmapFactory.Options o = new BitmapFactory.Options();
   o.inSampleSize = 2;
   Bitmap bit = BitmapFactory.decodeStream(inputStream,null,o);
   Bitmap scaled = Bitmap.createScaledBitmap(bit, 200, 200, true);
   bit.recycle();
   return scaled;
like image 570
Vinoth Avatar asked Feb 26 '11 14:02

Vinoth


2 Answers

To get bitmap dimensions, you can simply use:

To get height -> bitmap.getHeight() To get width -> bitmap.getWidth()

like image 61
Aakash Anuj Avatar answered Oct 05 '22 18:10

Aakash Anuj


Use inJustDecodeBounds field of BitmapFactory.Options to get bitmap dimensions.

like image 38
Asahi Avatar answered Oct 05 '22 17:10

Asahi