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
  • 79,279
  • 19
  • 185
  • 195
ajra
  • 31
  • 4

2 Answers2

0

This is a must read for handling Bitmaps in Android.

unexpectedvalue
  • 6,079
  • 3
  • 38
  • 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,907
  • 37
  • 114
  • 158