开发者

ViewFlipper : Bitmap size exceeds VM budget

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);
     imgPhot开发者_JAVA百科o.setImageBitmap(bitmapImage);
     vfImage.addView(imgPhoto);
}
vfImage.startFlipping();

Please help me.. Thank you...


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!


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜