收藏
回答

2d的canvas,wx.canvasToTempFilePath报错drawImage

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug wx.canvasToTempFilePath 工具 7.0.11 2.10.4

同一段代码,在三种情况下的报错

模拟器调试:代码中没使用drawImage,但是调用wx.canvasToTempFilePath就报错,

Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(CSSImageValue or HTMLImageElement or SVGImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap or OffscreenCanvas)'

预览:canvasToTempFilePath:fail invalid viewId

真机调试:Unhandled promise rejection TypeError: r.Canvas is not a constructor

wxml:
"2d" id="testCanvas">canvas>
js:
onReady: function () {
    console.log("here")
    const query=wx.createSelectorQuery()
    query.select("#testCanvas").fields({node:truesize:true}, function(res){
      console.log("here2", res)
      var canvas=res.node
      var ctx=canvas.getContext('2d')
      const dpr = wx.getSystemInfoSync().pixelRatio
      canvas.width = res.width * dpr
      canvas.height = res.height * dpr
      ctx.scale(dpr, dpr)
      ctx.fillRect(00100100)


      wx.canvasToTempFilePath({
        canvas"textCanvas",
        success:function(cttfp){
          console.log("here3", cttfp)
        },
        fail:function(cttfp){
          console.error("饼图绘制失败", cttfp)
        }
      })
    }).exec()
  },
回答关注问题邀请回答
收藏

2 个回答

登录 后发表内容
问题标签