如何在不刷新和更改图片的情况下仅从画布中删除路径和标记?



我通过画布上的某些坐标绘制路径和标记,在屏幕上显示图像。在图片上的某个坐标点。

Path path = new Path();
if (!isReady()) {
return;
} 
else if (routeList != null && nodeList != null) {
if (!routeList.isEmpty() && !nodeList.isEmpty()) {
// draw route
for (int i = 0; i < routeList.size() - 1; i++) {
PointF goal3 = new PointF(nodeList.get(routeList.get(i)).x, 
nodeList.get(routeList.get(i)).y);
PointF goal4 = new PointF(nodeList.get(routeList.get(i + 1)).x, 
nodeList.get(routeList.get(i + 1)).y);
sourceToViewCoord(goal3, vPin5);
sourceToViewCoord(goal4, vPin6);
path.moveTo(vPin5.x, vPin5.y);
path.lineTo(vPin6.x, vPin6.y);
//Draw path on canvas certain coordinate points
canvas.drawPath(path, paint);
}
PointF goal1 = new PointF(nodeList.get(routeList.get(0)).x,
nodeList.get(routeList.get(0)).y);
sourceToViewCoord(goal1, vPin3);
float vX1 = vPin3.x - (location_img.getWidth() / 2);
float vY1 = vPin3.y - location_img.getHeight() / 2;
//Draw marker certain coordinate point
canvas.drawBitmap(location_img, vX1, vY1, paint);
PointF goal2 = new PointF(nodeList.get(
routeList.get(routeList.size() - 1)).x, 
nodeList.get(routeList.get(routeList.size() - 1)).y
);
sourceToViewCoord(goal2, vPin4);
float vX2 = vPin4.x - (pin_red.getWidth() / 2);
float vY2 = vPin4.y - pin_red.getHeight();
// Draw bitmap on canvas certain coordinate points
canvas.drawBitmap(pin_red, vX2, vY2, paint);
}
}

您可以在另一个画布(位图)上绘制路径,并且仅根据自己的意愿在图像画布上绘制路径位图。正如Basile Perrenoud所说,重要的是不要在绘图过程中分配路径位图。例如,您可以在类实例化期间创建它,并在每次重绘时通过清理重用它。

saverestore方法仅存储转换矩阵和画布的剪辑区域(请参阅文档)。您无法从画布上删除像素,只需在其上绘制即可。如果在图像顶部添加了路径,则应进行仅绘制图像的调用。

请注意,只要您不重新加载或重新创建位图,在性能方面这没什么大不了的。

相关内容

  • 没有找到相关文章

最新更新