From 8a9ae2729e7ab7cfa37b27b91104f17054ccab84 Mon Sep 17 00:00:00 2001 From: xty Date: Thu, 25 Jul 2024 18:14:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84canvas=20=E4=B8=AD=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E4=B8=8D=E6=B8=85=E6=99=B0=E7=9A=84=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/component/canvas/canvas.uvue | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/pages/component/canvas/canvas.uvue b/pages/component/canvas/canvas.uvue index 9a254736..77ad7ffd 100644 --- a/pages/component/canvas/canvas.uvue +++ b/pages/component/canvas/canvas.uvue @@ -24,7 +24,7 @@ data() { const API_PATH = ["arc", "arcTo", "bezierCurveTo", "quadraticCurve", "moveTo", "lineTo", "rect", "clip", "pattern"] const API_DRAW = ["stroke", "strokeRect", "strokeText", "fill", "fillRect", "fillText", "drawImage", "drawImageLocal", "clearRect"] - const API_STATE = ["beginPath", "closePath", "restore", "reset", "setTransform", "transform", "rotate", "resetTransform", "save", "scale", "translate"] + const API_STATE = ["beginPath", "closePath", "reset", "transform", "rotate", "resetTransform", "save", "restore", "scale", "translate"] const API_PROPERTIES = ["setLineCap", "setLineJoin", "setLineWidth", "setMiterLimit", "setFillStyle", "setStrokeStyle", "setGlobalAlpha", "lineDash", "linearGradient", "radialGradient", "textAlign"] return { title: 'Context2D', @@ -124,9 +124,6 @@ case "scale": this.scale(); break; - case "setTransform": - this.setTransform(); - break; case "stroke": this.stroke(); break; @@ -362,7 +359,7 @@ const context = this.canvasContext! this.image = new Image(100, 100) - this.image!.src = 'https://web-ext-storage.dcloud.net.cn/uni-app-x/hello-uniappx-qrcode.png'; + this.image!.src = '../../../static/api.png'; // this.image!.src = 'https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/createPattern/canvas_createpattern.png'; // Only use the image after it's loaded this.image!.onload = () => { @@ -370,7 +367,7 @@ context.clearRect(0, 0, this.canvasWidth, this.canvasHeight) const pattern = context.createPattern(this.image!, "repeat") context.fillStyle = pattern - context.fillRect(0, 0, 64, 64) + context.fillRect(0, 0, 100, 100) context.restore() }; }, @@ -530,8 +527,6 @@ context.restore() }, - setTransform() { - }, rotate() { const context = this.canvasContext! @@ -623,7 +618,7 @@ }, save() { const context = this.canvasContext! - + context.clearRect(0, 0, this.canvasWidth, this.canvasHeight) context.save() context.beginPath() context.strokeStyle = '#00ff00' @@ -640,7 +635,8 @@ context.restore() }, restore() { - const context = this.canvasContext!; + const context = this.canvasContext!; + context.clearRect(0, 0, this.canvasWidth, this.canvasHeight); [3, 2, 1].forEach((item) => { context.save() context.beginPath() @@ -652,21 +648,21 @@ }, drawImageLocal() { const context = this.canvasContext! - + context.clearRect(0, 0, this.canvasWidth, this.canvasHeight) let image = new Image(100, 100) - image.src = '../../static/1.jpg' + image.src = '../../../static/uni.png' image.onload = () => { context.drawImage(image, 0, 0, 100, 100) } }, drawImage() { const context = this.canvasContext! - + context.clearRect(0, 0, this.canvasWidth, this.canvasHeight) let image = new Image(100, 100); image.src = 'https://web-ext-storage.dcloud.net.cn/uni-app-x/hello-uniappx-qrcode.png' image.onload = () => { context.drawImage(image, 0, 0, 100, 100) - uni.getElementById("page-canvas")?.appendChild(image) + // uni.getElementById("page-canvas")?.appendChild(image) } }, rect() { -- GitLab