0

我现在的目标是创建一个非矩形的位图,我也可以移动它。我已经创建了一个路径,我可以将它与画布的 clipPath 方法一起使用。是否可以移动那个clipPath?

另外,我这样做是最好的方法,还是有更好的方法来做到这一点?

这是我的绘图功能:

public void draw(Canvas c){

    // Paint object, for outline of clip Path.
    Paint p = new Paint();
    p.setStyle(Style.STROKE);
    p.setColor(Color.RED);

    // A currently defined path to clip the bitmap with
    Path clipPath = new Path();
    clipPath.moveTo(top_left.getX() + nodes.getNodeVals('L').getX(), top_left.getY() + nodes.getNodeVals('T').getY());
    clipPath.addPath(outline);

    c.save(); // Save the canvas (rotations, transformations, etc)
    c.clipPath(clipPath); // Create a clip region
    c.drawPath(clipPath, p); // Draw that clip region in red
    c.drawBitmap(img, top_left.getX(), top_left.getY(), null); // Draw the bitmap in the clip
    c.restore(); // Restore the canvas (rotations, transformations, etc)

}

我相信这clipPath.moveTo条线是我遇到问题的地方。基本上,它应该在用 moveTo 的 x 和 y 值定义的位置创建一个新路径(我相信我在其他地方正确设置了这些路径)。路径是预先创建的,并存储到 outline中,并且该addPath部分应将轮廓添加到clipPath

提前致谢!

4

1 回答 1

1

我不完全确定我是否完全了解您要做什么,但是如果您只是想将路径从其原始位置偏移,则 moveTo 不是要走的路,因为您添加的路径的坐标将是保留。

相反,您可以在 addPath 中添加偏移坐标:

//clipPath.addPath(outline);
clipPath.addPath(outline, dx, dy);

其中 dx 和 dy 是您的偏移量。

于 2012-09-07T12:11:48.113 回答