canvas画图片圆角
发布于 6 年前 作者 luona 6655 次浏览 来自 问答

此方法绘制圆角在ios系统上是正常的,在安卓下点的位置会偏移。

6 回复

你好,我这里有一份canvas画圆角的代码,在android上是ok的,请参考

roundRect1: function (x, y, w, h, r) {

// 开始绘制

const ctx = this .ctx

ctx.beginPath();

this .ctx.setFillStyle( '#ffffff' );

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 * );


ctx.lineTo(x + w, y + h - r);

ctx.lineTo(x + w - r, y + h);


ctx.arc(x + w - r, y + h - r, r, , 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);

this .ctx.fill();

this .ctx.setGlobalAlpha( 0.04 );

this .ctx.setShadow( '#000000' )

ctx.closePath();

this .ctx.draw( true )

return this ;

}

有用到createPattern吗? 为啥我的createPattern无效呢?@小样贼拽

实在不好意思,让你久等了,我们尽快处理

好的,谢谢

wechatide://minicode/GrMsOxm86xYs

回到顶部