美文网首页
关于Bitmap.createBitmap创建新的Bitmap,

关于Bitmap.createBitmap创建新的Bitmap,

作者: 伪装的狼 | 来源:发表于2022-03-24 17:00 被阅读0次

出现问题的代码如下:

val bitmap = BitmapFactory.decodeByteArray(nv21, 0, nv21.size)

val matrix = Matrix()
matrix.postRotate(Config.ROTATE_ANGLE)

val tempBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, false)

bitmap.recycle()

把bitmap回收之后,发现tempBitmap也被回收了,经过判断bitmap==tempBitmap的结果是true,然后查看源码,发现这么一段代码:

// check if we can just return our argument unchanged
if (!source.isMutable() && x == 0 && y == 0 && width == source.getWidth() && height == source.getHeight() && (m == null || m.isIdentity())) {
    return source;
}

如果source也就是传进来的Bitmap是可变的,设置新Bitmap宽高指定位置和原来的一样,并且m也就是传进来的Matrix,判断isIdentity为true,那么就返回原Bitmap,所以问题就清楚了。

相关文章

网友评论

      本文标题:关于Bitmap.createBitmap创建新的Bitmap,

      本文链接:https://www.haomeiwen.com/subject/upqljrtx.html