天天看點

微信小程式将拍攝的圖檔轉為base64字元串

1.将相機拍攝的轉為base64字元串

takePhoto: function() {
    const ctx = wx.createCameraContext()
    ctx.takePhoto({
      quality: 'high',
      success: (res) => {

        console.log(wx.getFileSystemManager().readFileSync(res.tempImagePath, "base64"))

      }
    })
  }      

2.将使用者從本地相冊選取的轉為base64字元串

transformBase(res) {
    let that = this;
    var FSM = wx.getFileSystemManager();
    //循環将得到的圖檔轉換為Base64
    for (let r in res.tempFilePaths) {
      // console.log(res.tempFilePaths[r])
      FSM.readFile({
        filePath: res.tempFilePaths[r],
        encoding: "base64",
        success: function(data) {
          let Working = data.data;
          that.getBase64ImageUrl(Working)
        }
      });
    }
  },      

繼續閱讀