2012-05-05 105 views
0

如何刪除android中的位圖?我創建了一個名爲「太陽」的位圖,但只要我完成了一個穿過屏幕的人,我想添加一個名爲「moon」的新位圖,但它只是在太陽頂部創建的,我怎麼能刪除太陽位圖?這是我的行走人的代碼。在android中刪除位圖

switch (counter) 
    { 

    case 0: 
     skyRect.set(0, 0, canvas.getWidth(), 400); 
     canvas.drawRect(skyRect, sky); 
     canvas.drawBitmap(AndroidDude, changingX, (canvas.getHeight()/2 - (AndroidDude.getHeight()/2)), null); 
     if (changingX < canvas.getWidth()) 
     { 
      changingX += 10; 
     } 
     else 
     { 
      changingX = 0; 
      sunChangingX = 0; 
      counter++; 
     } 

     grassRect.set(0, 400, canvas.getWidth(), canvas.getHeight()); 
     canvas.drawRect(grassRect, grass); 
     canvas.drawBitmap(cloud, 100, 50, null); 
     canvas.drawBitmap(cloud, 700, 100, null); 
     canvas.drawBitmap(sun, (canvas.getWidth() - sun.getWidth()), 0, null); 
     invalidate(); 
     break; 

    case 1: 
     //Remove sun and clouds here? 
     canvas.drawBitmap(moon, (canvas.getWidth() - moon.getWidth()), 0, null); 
     canvas.drawBitmap(AndroidDude, changingX, (canvas.getHeight()/2 - (AndroidDude.getHeight()/2)), null); 
     if (changingX < canvas.getWidth()) 
     { 
      changingX += 10; 
     } 
     else 
     { 
      changingX = 0; 
      counter++; 
     } 
     grassRect.set(0, 400, canvas.getWidth(), canvas.getHeight()); 
     canvas.drawRect(grassRect, grass); 
     canvas.drawBitmap(cloud, 100, 50, null); 
     canvas.drawBitmap(cloud, 700, 100, null); 
     canvas.drawBitmap(sun, sunChangingX, 0, null); 
     invalidate(); 
     break; 
    } 

回答

1

將您的背景(天空和草地)重繪到您想要移除的位圖上。進行刷新功能。

0

你只是在舊的東西上繪製新的東西。如果您需要「擦除」某些內容,則只需重新繪製背景。

0
Canvas.drawColor(Color.WHITE); 

您可以清潔畫布這樣 你可以用WHITE顏色繪製矩形。

//或任何你的畫布顏色

它會看起來像畫布是空白的。

並再次繪製你想要的。

您的輸出將以白色顯示。