[英]Leak of memory with a rescale of bitmap
Bitmaps
始终存储在设备的“ 堆内存”中 ,而设备的堆内存负担不起该数量的Bitmaps
,这可能是您尝试以相同分辨率的图像工作的方式, 因此 ,首先,请尝试使用您的应用来增加堆清单,然后尝试使用这种方法来调整Bitmaps
大小:
public static Bitmap scaleBitmap(Bitmap bitmapToScale, float newWidth, float newHeight) {
if(bitmapToScale == null)
return null;
//get the original width and height
int width = bitmapToScale.getWidth();
int height = bitmapToScale.getHeight();
// create a matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(newWidth / width, newHeight / height);
// recreate the new Bitmap and set it back
return Bitmap.createBitmap(bitmapToScale, 0, 0, bitmapToScale.getWidth(), bitmapToScale.getHeight(), matrix, true);
}
如果这也不起作用,那么,您必须进行以下一项操作:
提示:回收位图会将其完全从堆内存中删除,因此,出现"cannot draw recycled bitmaps"
错误是合乎逻辑的,因此,如果要recycle
它然后在应用程序中使用它,则必须将其存储在首先是类似ArrayList<Bitmaps>
东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.