收藏
回答

请问如何把画布图片生成到图片url呢?


//wxml部分
<canvas type="2d" canvas-id="ceshier" id="ceshierr"style="height:{{bili_hh}}rpx;width:600rpx;"></canvas>
//js部分
canvas_pic(url,width,height){
    var then=this
    var bili=parseInt(height/width*300)
    this.setData({bili_hh:parseInt(height/width*600)})
    const query = wx.createSelectorQuery()
    query.select('#ceshierr')
      .fields({ nodetruesizetrue })
      .exec((res) => {
        const canvas = res[0].node
        const ctx = canvas.getContext('2d')
        const dpr = wx.getSystemInfoSync().pixelRatio
        var img = canvas.createImage()
        canvas.width = res[0].width * dpr
        canvas.height = res[0].height * dpr
        img.src=url
        img.onload=()=>{
          ctx.drawImage(img,0,0,300,bili)
        }
        ctx.scale(dpr, dpr)
        ctx.fillRect(00100100)
    })
  },

以上是代码,想生成图片url,不知道加在哪里。求大神帮助
wx.canvasToTempFilePath({
  x: 100,
  y: 200,
  width: 50,
  height: 50,
  destWidth: 100,
  destHeight: 100,
  canvasId: 'ceshierr',
  success(res) {
    console.log(res.tempFilePath)
  }
})

官方写2.90版本后,加在darw()里面,不知道哪个地方是darw,下面这个代码请问如何加到上面 把图片生成url呢?
回答关注问题邀请回答
收藏

2 个回答

登录 后发表内容