我正試圖在畫布的每一片上創建一個帶有圖像的輪盤。到目前爲止,我成功地創建了一個圓圈並旋轉了該圓圈。下面是一個示例代碼:如何在畫布圓片中添加圖片?
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var radius = 100;
for (var i = 0; i < 8; i++) {
ctx.beginPath();
ctx.fillStyle = 'rgb(' + Math.floor(255 - 42.5 * i) + ', 95, 180)';
// We have to add this, otherwise, it will fill the minimum area needed to fill the arc
ctx.moveTo(300, 300);
ctx.arc(300, 300, radius, i * Math.PI/4, (i + 1) * ((Math.PI/4)), false);
ctx.closePath();
ctx.fill();
}
ctx.stroke();
#myCanvas {
border: 1px solid #d3d3d3;
}
<canvas id="myCanvas" width="500" height="500">
Your browser does not support the HTML5 canvas tag.
</canvas>
它創建片的圓。現在我想要做的是將圖像放入這些切片中。我使用了drawImage(),但它沒有達到我的目的。所以如果有人知道任何解決方法,請親切地回答。我被困在這個問題上已經有4天了。
你能有一個弧形裁剪圖像? –
我還沒有裁剪圖像,但我得到了我想添加圖像的弧線。 – Usman