canvas 画 圆角矩形

圆角矩形
drawRoundedRect(ctx, x, y, width, height, radius, type) {
           
            ctx.moveTo(x, y + radius);
            ctx.beginPath();
            ctx.arc(x + radius, y + radius, radius, Math.PI, 1.5 * Math.PI);
            ctx.arc(x + width - radius, y + radius, radius, 1.5 * Math.PI, 2 * Math.PI);
            ctx.arc(x + width - radius, y + height - radius, radius, 0, 0.5 * Math.PI);
            ctx.arc(x + radius, y + height - radius, radius, 0.5 * Math.PI, Math.PI);
            ctx.closePath();
            const method = type || 'stroke'; // 默认描边,传入fill即可填充矩形
            ctx[method]();
        },
原文地址:https://www.cnblogs.com/Running00/p/14657245.html