我现在的目标是创建一个非矩形的位图,我也可以移动它。我已经创建了一个路径,我可以将它与画布的 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
。
提前致谢!