选择图片,将图片进行base64编码格式转换
bindChooseImg(e) {
var that =this
wx.chooseImage({
success: res => {
wx.getFileSystemManager().readFile({
filePath: res.tempFilePaths[0], //选择图片返回的相对路径
encoding: 'base64', //编码格式
success: res => { //成功的回调
that.setData({
ImgUrl:res.data
})
}
})
}
})
}
将base64转换为图片显示
getBase64ImageUrl: function () {
let that = this
//获取到ImgUrl
var base64 = that.data.ImgUrl;
base64 = JSON.stringify(base64 )
// 通过微信小程序自带方法将base64转为二进制去除特殊符号,再转回base64
base64 = wx.arrayBufferToBase64(wx.base64ToArrayBuffer(base64))
const ImgUrl = base64 ;
},