收藏
回答

iphone 中微信小程序中 canvas为什么无法绘制出图形?

iphone14 plus 小程序中 canvas无法绘制出图形,在模拟器和小米10中正常。

微信版本8.0.45

ios17.2.1


实例代码如下:

onReady: function (){

wx.createSelectorQuery()

          .select('#myCanvas')

          .fields({ node: true, size: true })

          .exec(res=>{

            var res0 = res[0];

            let ctx = res0.node.getContext('2d');  //getContext返回Canvas 的绘图上下文

            let canvas = res0.node;

            MainCanvasContext = ctx;

            //通过设备像素比等重新绘制宽高

            const dpr = wx.getSystemInfoSync().pixelRatio

            console.log(dpr);

            canvas.width = res0.width * dpr   //设置物理像素宽度

            canvas.height = res0.height * dpr

            ctx.scale(dpr, dpr)


            ctx .fillStyle="#FF0000";

            ctx .fillRect(0,0,100,100);

      })

}


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

1 个回答

  • Demons
    Demons
    01-05

    请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。

    01-05
    有用
    回复
登录 后发表内容