我需要将大视图(宽度和高度为1920x840)转换为位图。我在内存大小较小的低端设备上遇到 java.lang.OutOfMemoryError 异常。我试过这段代码。
setDrawingCacheEnabled(true);
buildDrawingCache();
Bitmap b = getDrawingCache();
if (b == null) {
int width = getLayoutParams().width;
int height = getLayoutParams().height;
//here i am getting out of memory exception
b = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
draw(c);
}
destroyDrawingCache();
setDrawingCacheEnabled(false);
return b;