Archive

Posts Tagged ‘copy’

Copy Bitmap object to avoid references

September 10, 2011 2 comments

If you assign value of a Bitmap to the other one, it means you have create a reference to the source Bitmap. Hence, if either one is recycled, the other one certainly reference to the already-recycled Bitmap object in memory, which might cause some problems like: Exception on Bitmap, throwIfRecycled.

In some case, you probably want to copy a Bitmap object to a new one, here the trick:

Bitmap src = .....<allocated the source Bitmap>
Bitmap newBitmap = src.copy(src.getConfig(), src.isMutable() ? true : false);

Pretty much simple!
@Remember to recycle each one after used.

Cheers,
Pete Houston