-2

I used Volley library and I got this error. I used ListView to display. The application doesn't stop if I don't scroll down my list view.

I have read almost all threads about "OOM" in stackoverflow. I didn't find any useful. My application gets json string which is base 64 encoded image from web. I decode the string into byte array and I decode via bitmapfactory. I display the bitmap.

Dan
  • 9,391
  • 5
  • 41
  • 73
bbb
  • 1
  • 2

1 Answers1

0

if you want to display multiple bitmap in one activity you should only display thumbnails of these bitmaps in order to avoid Out Of Memory Error. You could do something like this :

 Bitmap getThumbnailFromBitmap(bitmap) {
     int width = bitmap.getWidth();
     int height = bitmap.getHeight();
     int max = Math.max(width, height);
     if (max>512) {
            int thumbWidth = Math.round((512f/max)* width);
            int thumbHeight = Math.round((512f/max)* height);
            Bitmap thumbnail = ThumbnailUtils.extractThumbnail(bitmap, thumbWidth , thumbHeight);
            bitamp.recycle();
            return thumbnail ;
     } else {
            return bitmap ;
     }

}
David N
  • 509
  • 4
  • 12
  • Not working bro ... My code byte[] decodedString = Base64.decode(getimage(), Base64.DEFAULT); Bitmap bm = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); Bitmap b = getThumbnailFromBitmap(bm); iv.setImageBitmap(b); iv is imageview. Error : Width and Height must be > 0 . – bbb Oct 14 '14 at 14:27