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();//循环将得到的图片转换为Base64for (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