小程序createCanvasContext生成的临时文件wxfile:// downloadFile:fail url scheme is inval
一、定义:this.ctx = wx.createCanvasContext('myCanvas', this)
二、绘制、this.ctx.draw(false, () => {
wx.canvasToTempFilePath({
success:返回的临时地址为wxfile://,下载时提示downloadFile:fail url scheme is inval
})
})
如果要保存绘制好的canvas,可以直接使用 wx.saveImageToPhotosAlbum保存
wx.saveImageToPhotosAlbum({ filePath: res.tempFilePath })
this.ctx = wx.createCanvasContext('myCanvas', this) this.ctx.draw(false, () => { wx.canvasToTempFilePath({ canvasId: 'myCanvas', success: (res) => { console.log('in canvasToTempFilePath'); // 在H5平台下,tempFilePath 为 base64 // console.log('图片已保存至本地:', res.tempFilePath) this.posterUrl = res.tempFilePath; this.$emit('on-success', res.tempFilePath) }, fail: (res) => { console.log(res) } }, this) })