微信小程序將拍攝的圖片轉爲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)
        }
      });
    }
  },

參考:

https://www.jb51.net/article/167907.htm

https://www.cnblogs.com/jessie-xian/p/11572028.html

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章