-3

I take an image with camera an store it in the sd card, the image stored must be upload from sd card to an imageView like that:

myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
ImageView _image=(ImageView)view.findViewById(R.id.imageCarte);
_image.setImageBitmap(myBitmap);

but i have this error:

05-05 08:23:20.593: E/AndroidRuntime(1936): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget.

can anyone help me. thanks

MByD
  • 135,866
  • 28
  • 264
  • 277
ajra
  • 31
  • 4
  • Scale the bitmap before you try and set it to the ImageView, it's too large at the moment as the error says – BeRecursive May 05 '12 at 09:38
  • 1
    as I already said (yesterday) similar questions are posted at least twice a day. Please first check related questions before posting here. The answer is basically pointing to here: http://developer.android.com/training/displaying-bitmaps/index.html – Boris Strandjev May 05 '12 at 09:39
  • possible duplicate of [java.lang.OutOfMemoryError: bitmap size exceeds VM budget - Android](http://stackoverflow.com/questions/1949066/java-lang-outofmemoryerror-bitmap-size-exceeds-vm-budget-android) – Boris Strandjev May 05 '12 at 09:39
  • 1
    search this question, this question was asked 100 times and already solution available do some googling... try this....http://stackoverflow.com/search?q=[android]+java.lang.OutOfMemoryError – MAC May 05 '12 at 09:40
  • Another popular: duplicate http://stackoverflow.com/questions/477572/android-strange-out-of-memory-issue-while-loading-an-image-to-a-bitmap-object – Boris Strandjev May 05 '12 at 09:40

1 Answers1

0

Using BitmapFactory in mobile is a memory consuming process. This problem will arise when you are trying to decode a lot of images continuously. As in java there is no option to free the memory allocated to the variable " myBitmap ". So make sure that these types of variables are set to null after using it.

Also try to use

System.gc() to clear the garbage collection.

If an error is thrown while executing "_image.setImageBitmap(myBitmap);" line then try to reduce the image size before displaying

Ashwin Krishnamurthy
  • 3,750
  • 3
  • 27
  • 49
DAC84
  • 421
  • 1
  • 8
  • 20