阅读 31

微信小程序canvas模糊解决

需要将canvas宽高乘像素比,还要对canvas进行缩放,官方demo给出了相关写法

const query = wx.createSelectorQuery()
  query.select('#myCanvas')
    .fields({ node: true, size: true })
    .exec((res) => {
      const canvas = res[0].node
      const ctx = canvas.getContext('2d')

      const dpr = wx.getSystemInfoSync().pixelRatio
      //宽高乘像素比
      canvas.width = res[0].width * dpr 
      canvas.height = res[0].height * dpr
      //再缩放
      ctx.scale(dpr, dpr)
      ctx.fillRect(0, 0, 100, 100)
    })
复制代码
文章分类
前端
文章标签