如何将边框半径应用于 canvas 元素,如 div 使其成为圆形?

how to apply border radius to canvas element like div to make it circle?

我想像其他任何 div 一样制作 canvas 元素圈,但它不起作用。这是我的代码。请抢劫代码。 border-radius propoerty 做错了什么?

<canvas id="myCanvas" width="200" height="200" style="background-color:red;border:1px solid;border-radius:50%">

border-radius 属性 无法正常工作,就像我在 div 上申请的那样。实际上,我想创建 canvas 的矩形、正方形和圆形。请任何人帮助我

`

您的代码看起来不错。边框半径应该这样做,但是如果您使用 JavaScript 此方法可能会有所帮助:

var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.arc(100, 75, 50, 0, 2 * Math.PI);
ctx.stroke();