直接上代码
//保存图片
savePic:function(e){
let that = this;
let src = e.currentTarget.dataset.src;
wx.showModal({
title: '提示',
content: '确定保存二维码?',
success(res){
if (res.confirm) {
//方法一
// var aa = wx.getFileSystemManager();
// aa.writeFile({
// filePath: wx.env.USER_DATA_PATH + '/PATRIZIA PEPE.png',
// data: that.data.scene.slice(22),
// encoding: 'base64',
// success: res => {
// wx.saveImageToPhotosAlbum({
// filePath: wx.env.USER_DATA_PATH + '/PATRIZIA PEPE.png',
// success: function (res) {
// wx.showToast({
// title: '保存成功',
// })
// },
// fail: function (err) {
// }
// })
// }, fail: err => {
// }
// })
//方法二
wx.downloadFile({
url: that.data.imgUrl +'ewm.jpg',
success: function (res) {
console.log('res',res);
//图片保存到本地
wx.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success: function (data) {
wx.showToast({
title: '保存成功!',
})
},
fail: function (err) {
if (err.errMsg === "saveImageToPhotosAlbum:fail cancel") {
wx.showToast({
title: '保存失败!',
icon: 'none'
})
}
},
})
},
fail: function (res) {
wx.showModal({
title: '文件下载错误',
content: res.errMsg,
})
},
})
} else if (res.cancel) {
}
}
})
},
方法一中scene是可以需要图片转成base64的,这一步的话直接在线图片转base64即可。
方法二是https的图片路径 如果是http则不行。
此方法亲测有效