【发布时间】:2011-10-28 11:02:09
【问题描述】:
我想为我的游戏画布使用许多位图。
我不能Recycle位图,因为我必须为整个部分使用位图。
请提及一些优化代码以处理许多位图的指南,同时也为我的基于画布的游戏应用程序提供更快的性能。
目前我正在使用以下代码从可绘制资源中获取位图,
BitmapFactory.Options bfOptions=new BitmapFactory.Options();
bfOptions.inSampleSize = 1;
bfOptions.inDither=false; //Disable Dithering mode
bfOptions.inPurgeable=true; //Tell to gc that whether it needs free memory, the Bitmap can be cleared
bfOptions.inInputShareable=true; //Which kind of reference will be used to recover the Bitmap data after being clear, when it will be used in the future
bfOptions.inTempStorage=new byte[16 * 1024];
myBitMap=BitmapFactory.decodeResource(getResources(),ID, bfOptions);
我目前正在关注这个code 在画布上绘图。
图像在 sprite 中,因此在尝试加载许多 sprite 时会出现问题。
在此代码链接中,MainGamePanel.java 正是我正在做的。对于位图解码,我使用上述方法。
【问题讨论】:
-
您需要发布一些代码供人们提供优化指南。
标签: android bitmap out-of-memory