pyq:function(){
var that =this
wx.showLoading({
title: '请稍后...',
})
wx.request({
url: app.url +'addScan',
daya:{
page:"pages/detail/detail",
one:that.data.detail.id,
two:that.data.toptjm
},
success:function(res){
console.log(res.data)
wx.hideLoading()
var context = wx.createCanvasContext('mycanvas', this)
context.drawImage(res.data, 50, 20, 200, 200)
context.setFillStyle('#676050')
context.setFontSize(18)
context.setTextAlign('center')
context.fillText("优趣商城",150,260)
context.setFontSize(14)
context.fillText(that.data.detail.name, 150, 300)
context.setFontSize(12)
context.fillText("立即扫码选购", 150, 380)
context.draw(true, wx.canvasToTempFilePath({
canvasId: 'mycanvas',
success: function (res) {
console.log(res);
// wx.saveImageToPhotosAlbum({
// filePath: res.tempFilePath,
// success(result) {
// console.log(result)
// wx.showToast({
// title: '图片保存成功',
// icon: 'success',
// duration: 2000
// })
// }
// })
that.setData({
scans: 1
})
}
}));
}
})
},
|
wx.canvasToTempFilePath最好也加个200的延时,绘制多内容在性能低的安卓机下,因为draw是个异步的,经常失败
好的,谢谢
ctx.draw(false, function() {
console.log('绘制完成');
在这里再去调用
wx.canvasToTempFilePath
});
好的,谢谢