异常:trying to use a recycled bitmap android.graphics.Bitmap
概意:试图使用已经recycled的Bitmap
一般情况下我们在对Bitmap进行Matrix的各种缩放、平移等处理,然后createBitmap,再对之前的Bitmap进行recycle处理。
例如:
Bitmap oldBitmap= BitmapFactory.decodeFile(pathName);
Matrix matrix = new Matrix();
matrix.setScale(0.5f, 0.5f);
Bitmap newBitmap= Bitmap.createBitmap(bitmapDecode, 0, 0,
oldBitmap.getWidth(), oldBitmap.getHeight(), matrix, true);
if(!oldBitmap.isRecycled()){
oldBitmap.recycle();
}
异常的根本问题出在“Bitmap.createBitmap”函数这里:
/**
* Returns an immutable bitmap from subset of the source bitmap,
* transformed by the optional matrix. The new bitmap may be the
* same object as source, or a copy may have been made. It is
* initialized with the same density as the original bitmap.
*
* If the source bitmap is immutable