微信小程序图片的保存方法

微信小程序图片的保存方法:1、下载文件资源到本地。2、保存图片。

具体操作步骤:

1.下载文件资源到本地:客户端直接发起一个 http get 请求,返回文件的本地临时路径。

即:调用函数wx.downloadfile({})

2.保存图片到系统相册。

即:调用函数wx.saveimagetophotosalbum({})

具体代码如下:

.wxml

<button data-image='{{图片路径}}' bindtap="saveimage" >保存图片</button>

.js

saveimage: function (e) {

wx.downloadfile({

url: 服务器http请求 +图片路径,

success: function (res) {

var imagefilepath = res.tempfilepath;

if (!util.isnull(imagefilepath)) {

wx.saveimagetophotosalbum({

filepath: imagefilepath,

success: function (data) {

wx.showtoast({

title: "保存成功",

})

}, fail: function (res) {

wx.showtoast({

title: "保存失败",

})

}

})

}

},

})

},


赞(0)
未经允许不得转载:主机测评网 » 微信小程序图片的保存方法
分享到: 更多 (0)