错误之前的代码。imgSrc是一个远程地址,无法保存
wx.saveImageToPhotosAlbum({
filePath: that.data.imgSrc,
success(res) {
wx.showToast({
title: '保存成功',
icon: "none"
})
console.log(res);
},
fail(res) {
wx.showToast({
title: '保存失败',
icon: "none"
})
console.log(res);
}
})
解决办法:先使用getImageInfo获取图片以后,再调用save方法。地址采用getimageinfo获取到的path
wx.getImageInfo({
src: that.data.srcUrl,
success: function (res) {
var path=res.path;
wx.saveImageToPhotosAlbum({
filePath: path,
success(res) {
wx.showToast({
title: '保存成功',
icon: "none"
})
console.log(res);
},
fail(res) {
wx.showToast({
title: '保存失败',
icon: "none"
})
console.log(res);
}
})
}
})