canvasToTempFilePath
saveImageToPhotosAlbum
drawImage(src) {
let byclear = this.data.byclear;
let ctx = wx.createCanvasContext('canvasPoster', this)
ctx.drawImage(this.data.src, 0, 0, 601 * byclear, 809 * byclear)
wx.getImageInfo({
src: src,
success(res) {
console.log(res);
ctx.drawImage(res.path, 40 * byclear, 849 * byclear, 120 * byclear, 120 * byclear)
}
})
ctx.setFontSize(14)
ctx.fillText('xxxx', 240 * byclear, 869 * byclear)
ctx.setFontSize(12)
ctx.setFillStyle('#ffdc06')
ctx.setTextBaseline('bottom')
ctx.fillText('长按保存图片分享', 240 * byclear, 949 * byclear)
ctx.draw()
},
createQRCode() {
Api.UserApi.createQRCode({
page: 'pages/index/index',
scene: '123'
}).then(res => {
const fsm = wx.getFileSystemManager();
const buffer = wx.base64ToArrayBuffer(res);
const fileName = wx.env.USER_DATA_PATH + '/share_img.jpg'
fsm.writeFileSync(fileName, buffer, 'binary')
this.drawImage(fileName)
})
},
saveImg() {
wx.canvasToTempFilePath({
canvasId: 'canvasPoster',
success: (res) => {
wx.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success: (result) => {
wx.showToast({
title: '海报已保存,快去分享给好友吧。',
icon: 'none'
})
}
})
},
fail(err) {
console.log(err)
}
}, this)
},
远程图片canvas无法渲染
保存到相册下半部分黑色