//xxx.wxml
<button type="primary" class="save_image" bindtap='saveToPhone'>保存图片到本地</button>
//xxx.js
Page({
saveToPhone() {
wx.getImageInfo() { //获取图片信息
src: 'images/xxx.png', //图片的路径,支持网络路径、本地路径、代码包路径
success:(res)=> { //接口调用成功的回调函数
var result = {
width:res.width,
height:res.height,
path:res.path,
type:res.type
}
console.log(result);
wx.saveImageToPhotosAlbum({ //保存图片到系统相册
filePath: result.path,
success:(res)=> { //接口调用成功的回调函数
wx.showToast({
title: '保存成功',
})
},
fail:(res)=> { //接口调用失败的回调函数
wx.showToast({
title: '保存失败',
icon:'none'
})
}
})
},
fail:(res)=> { //接口调用失败的回调函数
console.log(res);
}
}
}
}
});
最后
以上就是含蓄巨人最近收集整理的关于微信小程序如何保存图片到本地?的全部内容,更多相关微信小程序如何保存图片到本地内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复