<canvas type="2d" id="canvas" style="width: 300px; height: 300px"></canvas>
wx.createSelectorQuery()
.select('#canvas')
.fields({
node: true
})
.exec(async res => {
const canvas = res[0].node
const ctx = canvas.getContext('2d')
const that = this
wx.canvasToTempFilePath({
//把当前画布指定区域的内容导出生成指定大小的图片
canvas: canvas, // canvas实例
success(res) {
that.imageUrl = res.tempFilePath
}
})
})
https://developers.weixin.qq.com/miniprogram/dev/api/canvas/wx.canvasToTempFilePath.html