我遇到了这个异常:
异常:java.lang.IllegalStateException:无法复制回收位图
我的代码是:
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,那显然是错误的!我做错了什么??
最佳答案
您实际上是在这一行之后调用 bitmap.recycle();
:
Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
关于android - 回收位图异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9071624/