canvas 2d 报错 toTempFilePath:fail invalid viewid?
发布于 5 年前 作者 qiaogang 2050 次浏览 来自 问答
模拟器没问题,真机一直报 toTempFilePath:fail invalid viewid?

业务是当前页面 需要点击进入别的页面填写内容,然后带参数返回 然后画海报保存

当前页面画直接画海报没问题,返回一直报 toTempFilePath:fail invalid viewid?
onReady() {
    this.drawImage()
  },
drawImagefunction () {
    let that = this
    const query = wx.createSelectorQuery()
    query.select('#myCanvas')
      .fields({
        nodetrue,
        sizetrue
      })
      .exec((res) => {
        const canvas = res[0].node
        const canvasRes = res[0]
        const ctx = canvas.getContext('2d')
        const dpr = wx.getSystemInfoSync().pixelRatio
        that.setData({
          canvas ,
          canvasRes,
          ctx,
          dpr
        })
      })
  },
  drawImageDetail() {
    try {
      let userInfo = this.data.userInfo
      let canvasRes = this.data.canvasRes
      let canvas = this.data.canvas
      let dpr = this.data.dpr
      let ctx = this.data.ctx
      let that = this
      canvas.width = canvasRes.width * dpr
      canvas.height = canvasRes.height * dpr
      ctx.scale(dpr, dpr)
      ctx.fillStyle = 'white'
      ctx.fillRect(00, canvas.width, canvas.height)
       ctx.font = '14px DINCondensed-Bold'
      ctx.fillStyle = '#BEC5CC'
      ctx.fillText(`生成海报`00);
         setTimeout(() => {
           
            wx.canvasToTempFilePath({
              canvas: canvas,
              success(res) {
                console.log(res.tempFilePath)
                
               
              },
              fail(res){
                console.log(res)
              }
            })
          }, 400)
      } catch (error) {
        console.log(error)
      }
    },
1 回复

canvas 2d不支持真机调试,可以使用真机预览

回到顶部