From d3b4836e79a8c5aed14055f7db651603dedff873 Mon Sep 17 00:00:00 2001 From: CPPAlien Date: Tue, 10 Jul 2018 19:47:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20Android=20=E6=9C=BA?= =?UTF-8?q?=E5=9E=8B=E4=B8=8A=E5=9C=86=E8=A7=92=E5=9B=BE=E7=89=87=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pen.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/pen.js b/lib/pen.js index 7b79ed1..31dae80 100644 --- a/lib/pen.js +++ b/lib/pen.js @@ -75,7 +75,10 @@ export default class Painter { _doBorder(borderRadius, width, height) { if (borderRadius && width && height) { const r = Math.min(borderRadius.toPx(), width / 2, height / 2); - this.ctx.setFillStyle("rgba(0, 0, 0, 0)"); + // 防止在某些机型上周边有黑框现象,此处如果直接设置 setFillStyle 为透明,在 Android 机型上会导致被裁减的图片也变为透明, iOS 和 IDE 上不会 + // setGlobalAlpha 在 1.9.90 起支持,低版本下无效,但把 setFillStyle 设为了 white,相对默认的 black 要好点 + this.ctx.setGlobalAlpha(0); + this.ctx.setFillStyle("white"); this.ctx.beginPath(); this.ctx.arc(-width / 2 + r, -height / 2 + r, r, 1 * Math.PI, 1.5 * Math.PI); this.ctx.lineTo(width / 2 - r, -height / 2); @@ -92,6 +95,7 @@ export default class Painter { getApp().systemInfo.platform === 'ios')) { this.ctx.clip(); } + this.ctx.setGlobalAlpha(1); } }