我有以下代码。
this.getGame().getGraphics().drawBitmap(Assets.playScreen_LaserBeamAnimation, new Rect(0, 0, 100, 750), new Rect(0, 0, 100, 750), null);
this.getGame().getGraphics().drawBitmap(Assets.playScreen_LaserBeamAnimation, new Rect(0, 200, 10, 800), new Rect(0, 0, 200, 600), null);
第一个渲染语句需要0.6 - 1 second
渲染。第二个左右1 millisecond
。
位图很大:968 KB
并加载了以下代码:
public Bitmap readAssetsBitmap(String filename) throws IOException {
try {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPurgeable = true;
Bitmap bitmap = BitmapFactory.decodeStream(assets.open(filename), null, options);
if(bitmap == null) {
WSLog.d(Game.GAME_ENGINE_TAG, this,"File cannot be opened: It's value is null");
throw new IOException("File cannot be opened: It's value is null");
}
else {
WSLog.d(Game.GAME_ENGINE_TAG, this,"File successfully read: " + filename);
return bitmap;
}
}
catch (IOException e) {
WSLog.d(Game.GAME_ENGINE_TAG, this,"File cannot be opened: " + e.getMessage());
throw new IOException("File cannot be opened: " + e.getMessage());
}
}
我希望读取图像和设置位图需要一些时间,但是渲染它的一个小区域不应该花费这么长时间(而且神秘地它只是第一次渲染调用)。
如何避免第一次渲染需要这么长时间?
注意:它与缩放无关(我相信)。