简体   繁体   中英

how can i “reset” the canvas (and the bitmap used to draw into) so i can draw a new bitmap into the canvas?

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

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

 if(this.backgroundImage!=null)

The error rised because the bitmap which will be drawn is null.

source Live Wallpaper + bitmap + canvas

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM