小程序保存图片到本地

转自: 小程序保存图片到本地

保存小程序图片到本地

wx.getImageInfo({
  src: '../images/shareimg.jpg',
  success: function (res) {
    console.log(res.path)
    wx.getSetting({
      success(res) {
        if (!res.authSetting['scope.writePhotosAlbum']) {
          wx.authorize({
            scope: 'scope.writePhotosAlbum',
            success() {
              wx.saveImageToPhotosAlbum({
                filePath: res.path,
                success(result) {
                  console.log(result)
                }
              })
            }
          })
        }
      }
    })
  }
})

下载图片保存到本地

wx.downloadFile({
  url: 'https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/logo_white_fe6da1ec.png',
  success: function (res) {

    wx.saveImageToPhotosAlbum({
      filePath: res.tempFilePath,
      success(result) {
        console.log(result)
      }
    })

    wx.saveFile({
      tempFilePath: res.tempFilePath,
      success: function (res) {
        console.log(res.savedFilePath) 
      }
    })
    
  }
})

你可能感兴趣的:(小程序)