1

I need to create a gallery type application. Where i need display many image and give the zooming and sliding effects.
Now I am using android.widget.Gallery and setting the image to imageview in the getview of my gallery Adapter class (extends BaseAdapter). Me set image using bitmap, which is set by the following code

Bitmap  mBitmap = BitmapFactory.decodeFile(imagePathArray.get(position));
imageview.setImageBitmap(mBitmap);

It works fine at first, but after moving to third or fourth image the application crash with the following error

  ERROR/AndroidRuntime(12184):  FATAL EXCEPTION: main
  ERROR/AndroidRuntime(12184):  java.lang.OutOfMemoryError: bitmap size exceeds VM budget 

at the decodeFile statement.

When i searched for bitmap size exceeds VM budget, i got a lot of solutions like android-strange-out-of-memory-issue. But all solutions are reducing the image quality.
What is the best method to display image in good quality and with less memory, that will not cause bitmap size exceeds VM budget?
Any suggestion?
Thank you

Community
  • 1
  • 1
Labeeb Panampullan
  • 34,521
  • 28
  • 94
  • 112

1 Answers1

2

The only solution you have is to load your bitmap at a smaller size (BitmapFactory.Options lets you resample a bitmap at load time), or try to recycle other large bitmaps you may have loaded and that you don't need anymore.

Romain Guy
  • 97,993
  • 18
  • 219
  • 200