У меня есть этот код и успешно обрезаны левый угол, но мне нужно обрезать все 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