我有這個代碼,併成功地挖空左角,但我需要裁剪此圖像的所有4個角落,可以用同一個對象來完成嗎?使用drawImage()畫布裁剪圖像的倍數?
我有這段代碼,併成功地挖空了左角,但我需要裁剪此圖像的所有4個角,它可以用同一個對象來完成嗎?
//Global variables
var myImage = new Image(); // Create a new blank image.
// Load the image and display it.
function displayImage() {
// Get the canvas element.
canvas = document.getElementById("myCanvas");
// Make sure you got it.
if (canvas.getContext) {
// Specify 2d canvas type.
ctx = canvas.getContext("2d");
// When the image is loaded, draw it.
myImage.onload = function() {
// Load the image into the context.
ctx.drawImage(myImage, 0, 0);
// Get and modify the image data.
changeImage();
}
// Define the source of the image.
myImage.src = "ice.jpg";
}
}
function changeImage() {
ctx.strokeStyle = "white";
ctx.lineWidth = "70";
ctx.beginPath();
ctx.arc(0,0,10,0*Math.PI,0.5*Math.PI);
ctx.closePath();
ctx.stroke();
}
</script>
</head>
<body onload="displayImage()">
<canvas id="myCanvas" width="200" height="200">
</canvas>
</body>
</html>
哦,我的上帝,你是最好的!!!! – tali