0

I didn't succeed in resolving this error:

java.lang.OutOfMemoryError: bitmap size exceeds VM budget.

My code is:

BitmapFactory.Options op = new BitmapFactory.Options();
myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath(),op);
ImageView _image = (ImageView)view.findViewById(R.id.imageCarte);

int width = myBitmap.getWidth();
int height = myBitmap.getHeight();
int halfWidth = width/2;
int halfHeight = height/2;
Bitmap bmHalf = Bitmap.createScaledBitmap(myBitmap, halfWidth, halfHeight, false);
_image.setImageBitmap(bmHalf);
Perception
  • 77,470
  • 19
  • 176
  • 187
ajra
  • 1
  • 1

2 Answers2

0

This is a must read for handling Bitmaps in Android.

unexpectedvalue
  • 6,049
  • 3
  • 36
  • 62
0

You can specify inSampleSize on your BitmapFactory.Options instance:

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

For example:

BitmapFactory.Options op = new BitmapFactory.Options();
op.inSampleSize = 2
myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath(),op);
ImageView _image = (ImageView)view.findViewById(R.id.imageCarte);
_image.setImageBitmap(myBitmap);
Amokrane Chentir
  • 29,280
  • 37
  • 112
  • 157