Canvas 我如何创建一个带有内部图像的圆弧的画布圆

Canvas 我如何创建一个带有内部图像的圆弧的画布圆,canvas,roulette-wheel-selection,Canvas,Roulette Wheel Selection,我必须做一个轮盘赌,但在彩色弧与数字,我需要把图像,我可以这样做吗 如果我们使用路径和剪辑,我们可以很容易地做到这一点 我们用直线和圆弧创建一条路径,然后剪裁该路径并在需要的地方绘制图像。记住保存和恢复画布。因为“剪裁”会将所有后续绘制和填充剪裁到您创建的路径 //This is for only one section of the circle and needs to be repeated //for all slices. var c = document.getElementByI

我必须做一个轮盘赌,但在彩色弧与数字,我需要把图像,我可以这样做吗

如果我们使用路径和剪辑,我们可以很容易地做到这一点

我们用直线和圆弧创建一条路径,然后剪裁该路径并在需要的地方绘制图像。记住保存和恢复画布。因为“剪裁”会将所有后续绘制和填充剪裁到您创建的路径

//This is for only one section of the circle and needs to be repeated 
//for all slices.
var c = document.getElementById("c");
var img = document.createElement("img");

var ctx = c.getContext("2d");
img.src="your-image"
img.onload = function(){run()}
function run(){
    ctx.arc(200,200,150,0,2*Math.PI);
    ctx.stroke();
    ctx.beginPath();
    ctx.moveTo(200,200);
    ctx.lineTo(350, 200);
    ctx.arc(200,200,150,0,Math.PI/2);
    ctx.lineTo(200, 200);
    ctx.stroke();
    ctx.save();
    ctx.clip();
    ctx.drawImage(img, 200,200);
    ctx.restore();
}

是的,这是可能的。为什么不共享您的代码,这样我们就可以查看一下,看看您需要在哪里进行更改。一把小提琴将是巨大的奖金。谢谢!我要试试看!