0

My goal right now is create a bitmap that is a non-rectangular shape, that I can also move. I have created a path that I can use as with canvas's clipPath method. Is it possible to move that clipPath around?

Also, am I doing this the best way, or is there a better way to accomplish this?

Here's my draw function:

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)

}

The clipPath.moveTo line is where I'm having my problem, I believe. Basically, it should be creating a new path that is at the location defined with the x and y values of moveTo (I believe I have those set correctly elsewhere). The path is created beforehand, and stored into outline, and the addPath part should be adding the outline to clipPath.

Thanks in advance!

dkniffin
  • 1,295
  • 16
  • 25

1 Answers1

1

I'm not entirely sure if I understand exactly what it is you are trying to do, but if you simply want to offset the path from its original position, moveTo is not the way to go since the coordinates of a path you add will be retained.

Instead, you can add the offset coordinates in your addPath:

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

where dx and dy are your offsets.

erikh
  • 146
  • 9