Bitmap bitmap=Bitmap.createBitmap(temp,0,0,width,height,matrix,true);
当用temp.recycle()方法时就会出现这个错误。
错误原因:
传入的temp图片和新的bitmap图片分辨率一样。createBitmap的源码就会直接返回temp对象,而不是新建一个bitmap对象,这样temp.recycle()被回收后,bitmap自然也被回收了。
解决办法:
把传入的图片换一个不同的分辨率,或者使width,height和生成matrix的width,height不同。可以采用以下方法:
if(newHeight==height&&newWidth==width){
height=height-1;//强制使新旧图片分辨率不同,防止temp和bitmap是同一对象
}
if(bitmap!=temp){
temp.recycle();
}