临时路径的图片是可以使用这个api保存到本地的。 我的代码片段在这里。 第一个图是保存下来的图片,第二个是代码截图,第三个是log截图, 第四个是保存成功的截图。
不过我的代码片段在公司测试的时候偶现bug: 保存下来的图片和预览的不一致。
代码片段: https://developers.weixin.qq.com/s/I7GECFmd7gbn




在开发工具上是https://协议开头,一旦切换到真机调试就成wxfile://协议
//导出成图片
btnImg: function () {
wx.canvasToTempFilePath({
destWidth: 500,
destHeight: 500,
canvasId: ‘canvasId’,
success: function (res) {
console.log(‘res.tempFilePath:’+res.tempFilePath);
wx.downloadFile({
url: res.tempFilePath,
success: function (res) {
wx.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success: function (data) {
wx.showModal({
title: ‘下载成功’,
content: ‘图片以保存至您的手机’,
})
},
fail: function () {
console.log(‘error’);
}
})
}
})
}
})
},

真机调试截图

开发者工具截图
