我通过画布上的某些坐标绘制路径和标记,在画面上显示图像。在图片上的某个坐标点。
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);
}
}
答案 0 :(得分:0)
save
和restore
方法仅存储转换矩阵和画布的剪辑区域(See the doc)。您无法从画布中删除像素,只需在其上绘制。如果您在图像顶部添加了路径,则应进行仅绘制图像的调用。
请注意,只要您不重新加载或重新创建位图,这在性能上并不是一件大事。
答案 1 :(得分:0)
您可以在另一个画布上绘制路径(位图),并且只根据您在图像画布上的愿望绘制路径位图。正如Basile Perrenoud所说,重要的是不要在绘图期间分配路径Bitmap。你可以,例如在类instanciation期间创建它,并在每次重绘时重复使用它。