收藏
回答

Context.drawImage 使用 HTMLCanvasElement 报错Failed?

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 or VideoFrame)

wx.createSelectorQuery()
      .select('#canvas'// 在 WXML 中填入的 id
      .fields({
        nodetrue,
        sizetrue
      })
      .exec((res) => {
        console.log(res)
        dpr = wx.getSystemInfoSync().pixelRatio
        canvas = res[0].node // 重点1
        // console.log(canvas)
        canvas.width = res[0].width * dpr
        canvas.height = res[0].height * dpr
        ctx.clearRect(00, canvas.width, canvas.height)
        ctx.beginPath();
        ctx.scale(dpr, dpr)
        bg = canvas.createImage()
        bg.src = '/img/lz.jpg'
        bg.onload = () => {
          ctx.drawImage(bg, 00)
        }
      })

ctx.drawImage(canvas,
      magnifyRectangle.x - magnifyGlassRadius, 
      magnifyRectangle.y - magnifyGlassRadius,
      magnifyRectangle.width, 
      magnifyRectangle.height,
      magnifyRectangle.x - 2 * magnifyGlassRadius, 
      magnifyRectangle.y - 2 * magnifyGlassRadius,
      scaledMagnifyRectangle.width,
      scaledMagnifyRectangle.height
    )
回答关注问题邀请回答
收藏

2 个回答

登录 后发表内容