1

I am using a ViewFlipper to show some images from db. I am taking the blob values to an ArrayList then, converting each byte array to bitmap.

And then I am setting these each bitmap to each Imageview of ViewFlipper. If the count of images is below 10, then it is working fine. But if it exceeds 10, then suddently it caught an Exception : OutOfMemoryException : Bitmap size exceeds VM budget.

When I use inSampleSize of BitmapFactory.Options, it is working fine.But I want to display the image with actual height and width. How can I do this without exception?

My code is :

ViewFlipper vfImage    = (ViewFlipper)findViewById(R.id.vfImage);
for(Photos objPhotos :arPhotos)
 {
     byte[] btImages = null;   
     Bitmap bitmapImage = null;
     btImages = objPhotos.getImage();
     ImageView imgPhoto= new ImageView(this);
     bitmapImage    = BitmapFactory.decodeByteArray(btImages, 0, btImages.length);
     imgPhoto.setImageBitmap(bitmapImage);
     vfImage.addView(imgPhoto);
}
vfImage.startFlipping();

Please help me.. Thank you...

Jomia
  • 3,414
  • 10
  • 46
  • 63

2 Answers2

0

You should think about unloading the bitmaps that are currently not shown, to keep in memory only those that are on the screen right now. Good luck!

Egor
  • 39,695
  • 10
  • 113
  • 130
  • How we should unload the images? before calling startFlipping() method, we sholud add all images in to the ViewFlipper. I think removing and adding again the imaegs is not possible with ViewFlipper. – Jomia May 12 '11 at 11:11
  • Every time you flip loop through the children of the ViewFlipper and set ImageView's drawable to null on every child except of that is currently shown. Sorry, don't have any code examples, just the idea. – Egor May 12 '11 at 11:54
0

Once you have completed using your bitmaps, try and make it null like this,

 Bitmap bitmapImage = null; 

Try adding the above line in the last line of your for loop. This means each and every time the bitmap is made null, which reduces the memory being captured by your bitmap. Also try providing

bitmapImage.recycle(); 

This will recycle the bitmap and provide you with free memory.

Also you can refer to my question here

Community
  • 1
  • 1
Andro Selva
  • 53,910
  • 52
  • 193
  • 240
  • i tried with recycle() function and making bitmap object to null. But yet could not solve the issue – Jomia Jun 07 '11 at 09:52