From 4adce6a6155541260892b91088e22236b4cbdcea Mon Sep 17 00:00:00 2001 From: 0JARVIS0 <709406687@qq.com> Date: Fri, 6 Nov 2020 16:07:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E9=A6=96=E6=AC=A1?= =?UTF-8?q?=E7=BB=98=E5=88=B6=E5=8F=AF=E8=83=BD=E5=87=BA=E7=8E=B0=E7=9A=84?= =?UTF-8?q?canvas=E5=B0=BA=E5=AF=B8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- painter.js | 78 +++++++++++++++++++++++++++--------------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/painter.js b/painter.js index f24fa86..db024fb 100644 --- a/painter.js +++ b/painter.js @@ -662,49 +662,49 @@ Component({ startPaint() { this.initScreenK(); + const { + width, + height + } = this.properties.palette; - this.downloadImages(this.properties.palette).then(async (palette) => { - const { - width, - height - } = palette; + if (!width || !height) { + console.error(`You should set width and height correctly for painter, width: ${width}, height: ${height}`); + return; + } - if (!width || !height) { - console.error(`You should set width and height correctly for painter, width: ${width}, height: ${height}`); - return; - } + let needScale = false; + // 生成图片时,根据设置的像素值重新绘制 + if (width.toPx() !== this.canvasWidthInPx) { + this.canvasWidthInPx = width.toPx(); + needScale = this.properties.use2D; + } + if (this.properties.widthPixels) { + setStringPrototype(this.screenK, this.properties.widthPixels / this.canvasWidthInPx) + this.canvasWidthInPx = this.properties.widthPixels + } - let needScale = false; - // 生成图片时,根据设置的像素值重新绘制 - if (width.toPx() !== this.canvasWidthInPx) { - this.canvasWidthInPx = width.toPx(); - needScale = this.properties.use2D; - } - if (this.properties.widthPixels) { - setStringPrototype(this.screenK, this.properties.widthPixels / this.canvasWidthInPx) - this.canvasWidthInPx = this.properties.widthPixels - } - - if (this.canvasHeightInPx !== height.toPx()) { - this.canvasHeightInPx = height.toPx(); - needScale = needScale || this.properties.use2D; - } - this.setData({ - photoStyle: `width:${this.canvasWidthInPx}px;height:${this.canvasHeightInPx}px;`, + if (this.canvasHeightInPx !== height.toPx()) { + this.canvasHeightInPx = height.toPx(); + needScale = needScale || this.properties.use2D; + } + this.setData({ + photoStyle: `width:${this.canvasWidthInPx}px;height:${this.canvasHeightInPx}px;`, + }, function () { + this.downloadImages(this.properties.palette).then(async palette => { + if (!this.photoContext) { + this.photoContext = await this.getCanvasContext(this.properties.use2D, 'photo'); + } + if (needScale) { + const scale = getApp().systemInfo.pixelRatio; + this.photoContext.width = this.canvasWidthInPx * scale; + this.photoContext.height = this.canvasHeightInPx * scale; + this.photoContext.scale(scale, scale); + } + new Pen(this.photoContext, palette).paint(() => { + this.saveImgToLocal(); + }); + setStringPrototype(this.screenK, this.properties.scaleRatio); }); - if (!this.photoContext) { - this.photoContext = await this.getCanvasContext(this.properties.use2D, 'photo'); - } - if (needScale) { - const scale = getApp().systemInfo.pixelRatio; - this.photoContext.width = this.canvasWidthInPx * scale; - this.photoContext.height = this.canvasHeightInPx * scale; - this.photoContext.scale(scale, scale); - } - new Pen(this.photoContext, palette).paint(() => { - this.saveImgToLocal(); - }); - setStringPrototype(this.screenK, this.properties.scaleRatio); }); },