修复 Android 机型上圆角图片无法显示问题

This commit is contained in:
CPPAlien 2018-07-10 19:47:41 +08:00
parent afe9cb1628
commit d3b4836e79

View File

@ -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);
}
}