Reputation: 1835
In short, is the following an inefficient way to rescale images in any way perhaps due to garbage collection?
playBg_ = BitmapFactory.decodeResource(res_, R.drawable.field);
playBg_ = Bitmap.createScaledBitmap(playBg_, screenWidth_, screenHeight_, false);
And would it then be better to do something like this?
Bitmap tempBmp = BitmapFactory.decodeResource(res_, R.drawable.field);
playBg_ = Bitmap.createScaledBitmap(tempBmp, screenWidth_, screenHeight_, false);
tempBmp.recycle();
Or is there a better way?
Thanks!
Upvotes: 0
Views: 163
Reputation: 1835
I found that the second method was required. The first method left too much memory wasted before garbage collection could get to it. I also found that I definitely need to call recycle on all my images prior to loading up new ones. Simply dereferencing them and expecting garbage collection to pick it up is not sufficient. I was constantly running out of memory due to this fact.
Upvotes: 0
Reputation: 294
Second way is better. But why are you decoding the Bitmap by yourself and changing its size?
If you want to display it as a background, just use
myBgView.setBackground(R.drawable.field);
on your activity parent view.
Upvotes: 0