1

I have a photo on disk with dimensions 2560 x 1920. This is often too large to load into memory, so I'm trying to use BitmapFactory.Options.inSampleSize to conserve memory. From the docs:

inSampleSize: If set to a value > 1, requests the decoder to subsample the original image, returning a smaller image to save memory.

This is how I use it:

BitmapFactory.Options optsDownSample = new BitmapFactory.Options();
optsDownSample.inSampleSize = 3;

Bitmap bmp = BitmapFactory.decodeFile(path, optsDownSample);

but the app still sometimes crashes on the last line there, and from logcat I can see it's trying to allocate ~5mb, and I suspect this is because the downsampling is not really being honored.

Anyone else know what could be going on here, am I using inSampleSize incorrectly?

Thanks

user291701
  • 38,411
  • 72
  • 187
  • 285

1 Answers1

0

I'm also struggling understanding how to use the BitmapFactory.Options, based on all the documentation I've read I believe you are just missing the optsDownSample.inJustDecodeBounds = false; as indicated on the Android Developers site.

Best of lucks!