From 4f7456f0f3a33f4376336af0e4744f023270f550 Mon Sep 17 00:00:00 2001 From: CPPAlien Date: Mon, 22 Mar 2021 17:01:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20canvas2d=20=E5=9C=A8ios=20=E4=BE=A7?= =?UTF-8?q?=E6=B8=B2=E6=9F=93=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- painter.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/painter.js b/painter.js index 2d854f3..7ba88cd 100644 --- a/painter.js +++ b/painter.js @@ -689,9 +689,7 @@ Component({ this.canvasHeightInPx = height.toPx(); needScale = needScale || this.properties.use2D; } - this.setData({ - photoStyle: `width:${this.canvasWidthInPx}px;height:${this.canvasHeightInPx}px;`, - }); + if (!this.photoContext) { this.photoContext = await this.getCanvasContext(this.properties.use2D, 'photo'); } @@ -701,10 +699,15 @@ Component({ this.photoContext.height = this.canvasHeightInPx * scale; this.photoContext.scale(scale, scale); } - new Pen(this.photoContext, palette).paint(() => { - this.saveImgToLocal(); + + this.setData({ + photoStyle: `width:${this.canvasWidthInPx}px;height:${this.canvasHeightInPx}px;`, + }, () => { + new Pen(this.photoContext, palette).paint(() => { + this.saveImgToLocal(); + }); + setStringPrototype(this.screenK, this.properties.scaleRatio); }); - setStringPrototype(this.screenK, this.properties.scaleRatio); }); }, @@ -776,8 +779,8 @@ Component({ wx.canvasToTempFilePath({ canvasId: 'photo', canvas: that.properties.use2D ? that.canvasNode : null, - destWidth: that.canvasWidthInPx * getApp().systemInfo.pixelRatio, - destHeight: that.canvasHeightInPx * getApp().systemInfo.pixelRatio, + destWidth: that.canvasWidthInPx, + destHeight: that.canvasHeightInPx, success: function (res) { that.getImageInfo(res.tempFilePath); },