<canvas type="2d" canvas-id="ceshier" id="ceshierr"style="height:{{bili_hh}}rpx;width:600rpx;"></canvas>
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({ node: true, size: true })
.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(0, 0, 100, 100)
})
},
以上是代码,想生成图片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呢?
lingcun(){
console.log('执行生成')
wx.canvasToTempFilePath({
// canvasId:'ceshierr',
canvas:this.cavas,
success(res) {
console.log(res)
},
fail(r){
console.log('导出错误',r)
}
})
}
这个另存不出来哎