再生位异常 [英] Recycled bitmap exception
本文介绍了再生位异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得到这个异常:
例外:java.lang.IllegalStateException:无法复制一个循环位图
Exception: java.lang.IllegalStateException: Can't copy a recycled bitmap
我的code是:
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int newWidth;
int newHeight;
if (width >= height) {
newWidth = Math.min(width,1024);
newHeight = (int) (((float)newWidth)*height/width);
}
else {
newHeight = Math.min(height, 1024);
newWidth = (int) (((float)newHeight)*width/height);
}
float scaleWidth = ((float)newWidth)/width;
float scaleHeight = ((float)newHeight)/height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
switch (orientation) {
case 3:
matrix.postRotate(180);
break;
case 6:
matrix.postRotate(90);
break;
case 8:
matrix.postRotate(270);
break;
}
Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
bitmap.recycle();
try {
bitmap = resizedBitmap.copy(resizedBitmap.getConfig(), true);
}
catch (Exception e) {
Log.v(TAG,"Exception: "+e);
}
如果该异常是告诉我,我已经回收的 resizedBitmap 的,这显然是错误的!我在做什么错了?
If the exception is telling me that I've recycled resizedBitmap, that is patently false! What am I doing wrong??
推荐答案
您实际上是调用 bitmap.recycle();
这行之后:
You are actually calling bitmap.recycle();
after this line:
Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
这篇关于再生位异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文