我收到错误java.lang.OutOfMemoryError: bitmap size exceeds VM budget
。Android位图创建OutOfMemory错误
创建用于手动绘制折线图的位图时会出现这种情况。
width = display.getWidth() - 10;
height = width * 4/5;
Bitmap emptyBmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
Bitmap charty = createMyGraphAndStuff(emptyBmap);
它看起来像分配的总内存大约700 Kb,不合理的数额。
我在文件中创建位图时看到了其他解决方案,但在这里我自己生成一个位图。我如何最小化内存占用?
这里的一些代码给你它正在做什么更好的主意:
public Bitmap DrawTheGraphAndStuff(Bitmap bitmap, String[] scores)
{
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
drawTheGridLines(canvas);
plotTheDataPoints(canvas , scores , "the title" , 0);
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
你为什么不发布你的“createMyGraphAndStuff(Bitmap b)”函数。顺便说一句,在这个名字! – L7ColWinters 2012-01-18 02:46:53
你可以粘贴你的'createMyGraphAndStuff'代码吗? – idiottiger 2012-01-18 02:58:50
什么是createMyGraphAndStuff? – 2012-01-18 03:19:46