When developing mini programs, sometimes there are many beautiful pictures in the mini program that users want to download , but long pressing to save has no effect. Take a screenshot? It also seems too low, so give users a good experience and the function of downloading images.
As shown below, you can trigger this method on the page. The red area is the path of the image.
The renderings are as follows:
bindseaveimage:function(){ wx.getImageInfo({ src: this.data.imagecode,//这里放你要下载图片的数组(多张) 或 字符串(一张) 下面代码不用改动 success: function (ret) { var path = ret.path; wx.saveImageToPhotosAlbum({ filePath: path, success(result) { console.log("成功"); wx.hideLoading(); wx.showToast({ title: '下载图片成功', duration: 2000, mask: true, }); }, fail(result) { console.log("失败,你取消了" + JSON.stringify(result)) console.log(path); wx.openSetting({ success: (res) => { console.log(res); } }) } }); } }); }
For more programming-related knowledge, please visit: Programming Teaching! !
The above is the detailed content of A brief discussion on how to implement the image download function in mini programs. For more information, please follow other related articles on the PHP Chinese website!