Ich möchte zwei kreisförmige Schnitte aus einem Bild austauschen und ihre Positionen tauschen und sie auf die Leinwand zeichnen. Ich habe jedoch Probleme, das zweite kreisförmige Bild zu zeichnen. Interessanterweise in second
, wenn Sie die erste Zeile auskommentieren, zeichnet es dieses Bild, andernfalls, wenn Sie es am Ende der Funktion werfen, zeichnet es nicht (mindestens oben). Wenn ich die erste Funktion auskommentiere, bekomme ich das Bild auf der Leinwand. Die erste Funktion wird immer vor der zweiten ausgeführt.Verkappte Bilder im Canvas-Bereich austauschen
function first() {
ctx.drawImage(imgBig, 0, 0);
ctx.beginPath();
ctx.arc(imgObj1.x + imgObj1.width/2, imgObj1.y + imgObj1.width/2, imgObj1.width/2, 0, 6.28, false);
ctx.clip();
ctx.stroke(); // the outline of circle
ctx.closePath();
ctx.drawImage(imgBig, imgObj2.x, imgObj2.y, imgObj2.width, imgObj2.height, imgObj1.x, imgObj1.y, imgObj1.width, imgObj1.height);
function second() {
// ctx.drawImage(imgCuttingBoard, 0, 0); // this will draw over canvas
ctx.beginPath();
ctx.arc(imgObj2.x + imgObj2.width/2, imgObj2.y + imgObj2.width/2, imgObj2.width/2, 0, 6.28, false);
ctx.clip();
ctx.closePath();
ctx.drawImage(imgCuttingBoard, imgObj1.x, imgObj1.y, imgObj1.width, imgObj1.height, imgObj2.x, imgObj2.y,
imgObj2.width, imgObj2.height); // this doesn't draw on top of the image (might be drawing underneath?)
// ctx.drawImage(imgCuttingBoard, 0, 0); // this will not draw over canvas here
}
Dank mit! Ich habe diese Antwort buchstäblich vor einer Sekunde gefunden. Problem war das Fehlen von .save() und .restore() Methoden. –