A brief discussion on how to implement the image download function in mini programs

青灯夜游
Release: 2021-06-01 09:15:24
forward
7717 people have browsed it

A brief discussion on how to implement the image download function in mini programs

Mini program picture download

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.

A brief discussion on how to implement the image download function in mini programs
The renderings are as follows:
A brief discussion on how to implement the image download function in mini programs

 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);
              }
            })
          }
        });
      }
    });
  }
Copy after login

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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template