E企盈营销工具技术服务商 热线:4006-838-530

【微信小程序】小程序保存图片到相册权限设置

E企盈直播平台营销卖货系统

微信小程序保存图片到相册可以分成两种:一种是保存网络图片,一种是保存本地图片保存网络图片:    var url = ‘网络图片路径’;     wx.downloadFile({      url: url,      success: function (res) {        var benUrl = res.tempFilePath;        //图片保存到本地相册        wx.saveImageToPhotosAlbum({          filePath: benUrl,          //授权成功,保存图片          success: function (data) {            wx.showToast({              title: ‘保存成功’,              icon: ‘success’,              duration: 2000            })          },          //授权失败          fail: function (err) {            if (err.errMsg) {//重新授权弹框确认                wx.showModal({                  title: ‘提示’,                  content: ‘您好,请先授权,在保存此图片。’,                  showCancel: false,                  success(res) {                    if (res.confirm) {//重新授权弹框用户点击了确定                      wx.openSetting({//进入小程序授权设置页面                        success(settingdata) {                          console.log(settingdata)                          if (settingdata.authSetting[‘scope.writePhotosAlbum’]) {//用户打开了保存图片授权开关                            wx.saveImageToPhotosAlbum({                              filePath: benUrl,                              success: function (data) {                                wx.showToast({                                  title: ‘保存成功’,                                  icon: ‘success’,                                  duration: 2000                                })                              },                            })                          } else {//用户未打开保存图片到相册的授权开关                            wx.showModal({                              title: ‘温馨提示’,                              content: ‘授权失败,请稍后重新获取’,                              showCancel: false,                            })                          }                        }                      })                    }                   }                })            }          }        })      }    })保存本地图片:    wx.chooseImage({      count: 1,// 默认9      sizeType: [‘original’, ‘compressed’],// 可以指定是原图还是压缩图,默认二者都有      sourceType: [‘album’, ‘camera’],// 可以指定来源是相册还是相机,默认二者都有      success: function (res) {        // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片        console.log(“choose image”)        console.log(res)        var tempFilePath = res.tempFilePaths[0]        wx.getImageInfo({          src: tempFilePath,          success: function (res) {            console.log(“get image info”)            console.log(res)            wx.saveImageToPhotosAlbum({              filePath: res.path,              success(res) {                console.log(“保存图片成功”)                console.log(res)                wx.showToast({                  title: ‘保存成功’,                  icon: ‘success’,                  duration: 2000                })              },              fail(err) {                console.log(‘失败’)                console.log(err)                if (err.errMsg == “saveImageToPhotosAlbum:fail cancel”) {                  wx.openSetting({                    success(settingdata) {                      console.log(settingdata)                      if (settingdata.authSetting[“scope.writePhotosAlbum”]) {                        console.log(‘获取权限成功,给出再次点击图片保存到相册的提示。’)                      } else {                        console.log(‘获取权限失败,给出不给权限就无法正常使用的提示’)                      }                    }                  })                }              }            })          }        })      }    })

赞(0) 打赏
未经允许不得转载:E企盈小程序开发-热线:4006-838-530 » 【微信小程序】小程序保存图片到相册权限设置
分享到: 更多 (0)
E企盈小程序直播营销卖货系统
E企盈直播平台营销卖货系统

评论 抢沙发

E企盈小程序开发

联系我们联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏