如何删除android中的位图?我已经创建了一个名为“sun”的位图,但是一旦我完成了一个人走过屏幕,我想添加一个名为“月亮”的新位图,但它只是在太阳顶部创建,我怎么能删除太阳位图?这是我行走的人的代码。
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;
}
答案 0 :(得分:1)
在要删除的位图上重绘背景(天空和草地)。刷新功能。
答案 1 :(得分:0)
你只是在旧的东西上画新东西。如果你需要“擦除”某些东西,你只需重新绘制背景。
答案 2 :(得分:0)
Canvas.drawColor(Color.WHITE);
或强>
你可以这样清理画布 你可以用 WHITE 颜色绘制矩形。
//或任何画布颜色
看起来画布是空白的。
再次画出你想要的东西。
您的输出将以白色显示。