我怎样才能“重置”画布(以及用于绘制的位图),以便我可以在画布中绘制新的位图?
当我尝试加载新地图时,我的 loadMap() 方法会生成 canvas.throwIfRecycled 异常。
当我开始游戏时,初始地图会加载并且工作正常,
只有当我尝试加载新地图时才会出现异常..
我如何“重置”画布和我用来绘制的位图,以便我可以重新开始使用它们?
这是我用来创建和绘制地图的内容:
picDest = Bitmap.createBitmap(width*tileSize, height*tileSize, Bitmap.Config.RGB_565);
canvas = new Canvas(picDest);
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
// process tile stuffs here ...
/*
col = ....:
row = ....;
*/
pic[x][y]= Bitmap.createBitmap(sheet, col*tileSize, row*tileSize, tileSize, tileSize);
canvas.drawBitmap(pic[x][y],x*tileSize,y*tileSize,bitmPaint);
}
}
基本上,一旦我创建并使用了 picDest 和画布,
当我想加载新地图时,我不知道如何重置所有内容
..tnx
My loadMap() method generate a canvas.throwIfRecycled exception when i try to load a new map.
When i start the game, the initial map loads and work fine though,
its only when i try to load a new map that i get the exception ..
how can i "reset" canvas and the bitmap i use to draw into, so i can startover fresh with them ?
here's what i use to create and draw my maps:
picDest = Bitmap.createBitmap(width*tileSize, height*tileSize, Bitmap.Config.RGB_565);
canvas = new Canvas(picDest);
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
// process tile stuffs here ...
/*
col = ....:
row = ....;
*/
pic[x][y]= Bitmap.createBitmap(sheet, col*tileSize, row*tileSize, tileSize, tileSize);
canvas.drawBitmap(pic[x][y],x*tileSize,y*tileSize,bitmPaint);
}
}
so basicaly once i created and used picDest and canvas,
i cannot figure how to reset it all for when i want to load a new map..
tnx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果你调用invalidate();它会重新绘制(因此重置它,并按照任何新的说明绘制任何内容)。
If you call invalidate(); it'll redraw (therefore reseting it, and following any new instructions to draw whatever).
我以前遇到过这种问题,我通过添加检查器解决了这个问题。
错误出现是因为将绘制的位图为空。
来源
动态壁纸+位图+画布
I've got that kind of problem before and I've got it solved by adding a checker
The error rised because the bitmap which will be drawn is null.
source
Live Wallpaper + bitmap + canvas