收藏
回答

canvas画图片圆角

框架类型 问题类型 API/组件名称 终端类型 操作系统 微信版本 基础库版本
小程序 Bug canvas 客户端 Android 6.6.5 1.9.97


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

回答关注问题邀请回答
收藏

6 个回答

  • 小程序运营专员 - cunjin
    小程序运营专员 - cunjin
    2018-04-28

    你好,我这里有一份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 ;

    }


    2018-04-28
    有用 2
    回复 1
    • Genuifx
      Genuifx
      2018-07-15

      我用你的代码画了,然后想用createPattern结果失败了,不知道是啥问题,这里的avatarUrl是getUserInfo拿回来的头像


      this.wxapi.downloadFile({url: avatarUrl})
      .then(({tempFilePath})=>{
        console.log(tempFilePath);
       
        let p = ctx.createPattern(tempFilePath, 'no-repeat');
        roundRect(ctx, 20, rpx2px(this.$hei + 50), rpx2px(100), rpx2px(100), rpx2px(8));
         
        ctx.fillStyle = p;
        ctx.fill();
        ctx.draw(true);
      });


      2018-07-15
      回复
  • Genuifx
    Genuifx
    2018-07-15

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

    2018-07-15
    有用
    回复
  • 小样贼拽
    小样贼拽
    2018-04-28

    好的,谢谢

    2018-04-28
    有用
    回复
  • 疯狂的小辣椒
    疯狂的小辣椒
    2018-04-28

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

    2018-04-28
    有用
    回复
  • 小样贼拽
    小样贼拽
    2018-04-09

    wechatide://minicode/GrMsOxm86xYs

    2018-04-09
    有用
    回复
  • 疯狂的小辣椒
    疯狂的小辣椒
    2018-04-09

    麻烦给个相关的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html),我们定位下问题

    2018-04-09
    有用
    回复
登录 后发表内容