From 9b4b63ea48c393e4fe85fcfa7eb04fa884dd7b8e Mon Sep 17 00:00:00 2001 From: luqc Date: Wed, 29 May 2019 13:39:04 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=B0=8F=E7=A8=8B=E5=BA=8F=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=B5=B7=E6=8A=A5][=E4=BF=AE=E6=94=B9][=E5=AE=89=E5=8D=93?= =?UTF-8?q?=E6=89=8B=E6=9C=BA=E7=BC=BA=E8=A7=92=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/canvas/index.js | 48 ++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/pages/canvas/index.js b/pages/canvas/index.js index 9f5c962..d3b76ab 100644 --- a/pages/canvas/index.js +++ b/pages/canvas/index.js @@ -140,7 +140,7 @@ Page({ ctx.setFillStyle("#fbfbfb"); ctx.fillRect(0, 0, that.data.windowWidth, that.data.windowHeight); ctx.drawImage(res.path, 0, 50, topImageWidth, topImageHeight); - that.roundRect(ctx, 15 * scale, 270 * scale, 325 * scale, 125 * scale, 10); + that.roundRect(ctx, 15 * scale, 270 * scale, 325 * scale, 125 * scale, 10* scale); that.drawOtherContent(ctx, scale, options); that.drawAvatarimg(ctx, scale); that.drawqrCode(ctx, scale); @@ -314,26 +314,32 @@ Page({ ctx.draw(true); }, //绘制圆角矩形 - roundRect: function(ctx, x, y, w, h, r) { - ctx.save(); - if (w < 2 * r) { - r = w / 2; - } - if (h < 2 * r) { - r = h / 2; - } - ctx.beginPath(); - // ctx.setStrokeStyle('white'); - ctx.setFillStyle('#fff') - ctx.setLineWidth(4); - ctx.moveTo(x + r, y); - ctx.arcTo(x + w, y, x + w, y + h, r); - ctx.arcTo(x + w, y + h, x, y + h, r); - ctx.arcTo(x, y + h, x, y, r); - ctx.arcTo(x, y, x + w, y, r); - ctx.fill(); - ctx.closePath(); - ctx.draw(true); + roundRect: function(ctx, x, y, w, h, r, c = '#fff') { + if (w < 2 * r) { r = w / 2; } + if (h < 2 * r) { r = h / 2; } + + ctx.beginPath(); + ctx.fillStyle = c; + + ctx.arc(x + r, y + r, r, Math.PI, Math.PI * 1.5); + ctx.moveTo(x + r, y); + ctx.lineTo(x + w - r, y); + ctx.lineTo(x + w, y + r); + + ctx.arc(x + w - r, y + r, r, Math.PI * 1.5, Math.PI * 2); + ctx.lineTo(x + w, y + h - r); + ctx.lineTo(x + w - r, y + h); + + ctx.arc(x + w - r, y + h - r, r, 0, Math.PI * 0.5); + ctx.lineTo(x + r, y + h); + ctx.lineTo(x, y + h - r); + + ctx.arc(x + r, y + h - r, r, Math.PI * 0.5, Math.PI); + ctx.lineTo(x, y + r); + ctx.lineTo(x + r, y); + + ctx.fill(); + ctx.closePath(); }, //获取商户优惠劵信息 getCouponList: function(id) {