From 1a6a08395c77251b49d5b770b9f957747369a128 Mon Sep 17 00:00:00 2001 From: 0JARVIS0 <709406687@qq.com> Date: Tue, 20 Oct 2020 17:58:42 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E5=A4=9A=E6=AC=A1?= =?UTF-8?q?=E7=BB=98=E5=88=B6=E5=AF=BC=E8=87=B4=E7=9A=84=E5=B0=BA=E5=AF=B8?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- painter.js | 26 ++++++++++++++++++-------- painter.wxml | 6 +++--- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/painter.js b/painter.js index f78a300..c2da727 100644 --- a/painter.js +++ b/painter.js @@ -668,19 +668,33 @@ Component({ return; } + let needScale = false; // 生成图片时,根据设置的像素值重新绘制 - this.canvasWidthInPx = width.toPx(); + 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 } - this.canvasHeightInPx = height.toPx(); + 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;`, }); - this.photoContext || (this.photoContext = await this.getCanvasContext(this.properties.use2D, 'photo')); - + 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(); }); @@ -784,10 +798,6 @@ Component({ that.canvasNode = res[0].node; const ctx = that.canvasNode.getContext('2d'); const wxCanvas = new WxCanvas('2d', ctx, id, true, that.canvasNode); - const dpr = Math.min(2, getApp().systemInfo.pixelRatio) - wxCanvas.width = res[0].width * dpr - wxCanvas.height = res[0].height * dpr - wxCanvas.scale(dpr, dpr) resolve(wxCanvas); }); } else { diff --git a/painter.wxml b/painter.wxml index c53935a..bd7a3b6 100644 --- a/painter.wxml +++ b/painter.wxml @@ -14,8 +14,8 @@ disable-scroll="{{true}}" /> - - + + From c26ff78fe51000bc1d084185fd94cb406592ebb9 Mon Sep 17 00:00:00 2001 From: 0JARVIS0 <709406687@qq.com> Date: Tue, 20 Oct 2020 19:36:03 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20used=E6=97=B6=E7=A6=81=E6=AD=A2dance?= =?UTF-8?q?palette=E4=B8=8Eaction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- painter.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/painter.js b/painter.js index c2da727..f24fa86 100644 --- a/painter.js +++ b/painter.js @@ -46,7 +46,7 @@ Component({ dancePalette: { type: Object, observer: function (newVal, oldVal) { - if (!this.isEmpty(newVal)) { + if (!this.isEmpty(newVal) && !this.properties.use2D) { this.initDancePalette(newVal); } }, @@ -72,7 +72,7 @@ Component({ action: { type: Object, observer: function (newVal, oldVal) { - if (newVal && !this.isEmpty(newVal)) { + if (newVal && !this.isEmpty(newVal) && !this.properties.use2D) { this.doAction(newVal, (callbackInfo) => { this.movingCache = callbackInfo }, false, true) @@ -232,6 +232,9 @@ Component({ }, doAction(action, callback, isMoving, overwrite) { + if (this.properties.use2D) { + return; + } let newVal = null if (action) { newVal = action.view @@ -622,6 +625,9 @@ Component({ }, initDancePalette() { + if (this.properties.use2D) { + return; + } this.isDisabled = true; this.initScreenK(); this.downloadImages(this.properties.dancePalette).then(async (palette) => { 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 3/3] =?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); }); },