代码改变世界

Android:Cannot generate texture from bitmap的原因

2013-04-16 17:30  王妞  阅读(4874)  评论(1编辑  收藏  举报

错误:Cannot generate texture from bitmap。界面的ImageView显示一片黑色。
原因:我是在调用Bitmap newBmp = Bitmap.createBitmap(originBmp, 0, 0, bmpW, bmpH, matrix, true)之后,就recycle originBmp, 谁知道当matrix.postScale(ratio, ratio)中的ratio = 1.0的时候,newBmp == originBmp, 所以此时不能recycle originBmp.

解决办法:

在recycle之前加一个判断语句:if(newBmp != originBmp)