Rounded corners on canvas images

I have a canvas with an image inside it. I am looking to put rounded corners on two corners of the image. I think that one of the global operators will use the way to do this, but I cannot understand how I will do it.

Any help would be appreciated.

+3
source share
1 answer

Instead of using the global operator, define the space that you want the image to go in (it should be a path that is a rectangle, except for rounded corners).

Then put this path in context before drawing the image, call .clip (), and then draw the image.

Then the image will be drawn with rounded corners at the two corners of the image.

, , .

:

ctx.save();
ctx.beginPath();
// use lineTo and BezierTo here to make the path you want, which is a rectangle the size of the image with two rounded corners.
ctx.closePath();
ctx.clip();

// draw the image
ctx.restore(); // so clipping path won't affect anything else drawn afterwards
+5

Source: https://habr.com/ru/post/1789656/


All Articles