时间:2019-05-07 来源:小程序工厂
付***:
//将canvas转换为图片保存到本地,然后将图片路径传给image图片的src
createNewImg() {
var that = this
var unit = this.data.screenWidth / 375
var context = wx.createCanvasContext('mycanvas')
var path = that.data.qtPaths
context.drawImage(path, 0, 0, 343 * unit, 220 * unit)
that.setMoney(context)
that.setName(context)
that.setQrcode(context)
//绘制图片
context.draw()
context.save()
//将生成好的图片保存到本地,需要延迟一会,绘制期间耗时
setTimeout(() => {
wx.canvasToTempFilePath({
canvasId: 'mycanvas',
success: function(res) {
wx.hideLoading()
that.setData({
imagePath: res.tempFilePath
})
},
fail: function(res) {
console.log(res.errMsg)
}
})
}, 2000)
},