小程序上传的图片怎么先转base64在传后台
let that = this ; wx.chooseImage({ success: function (res) { var tempFilePaths = res.tempFilePaths console.log(tempFilePaths[0]) let canvas = wx.createCanvasContext( 'myCanvas' ) // 1. 绘制图片至canvas canvas.drawImage(tempFilePaths[0], 0, 0, 75, 75) // 绘制完成后执行回调,API 1.7.0 canvas.draw() // 2. 获取图像数据, API 1.9.0 wx.canvasGetImageData({ canvasId: 'myCanvas' , x: 0, y: 0, width: 75, height: 75, success (res) { console.log( ":res" , res) // 3. png编码 let pngData = upng.encode([res.tempFilePaths[0]], 75, 75) // 4. base64编码 let base64 = wx.arrayBufferToBase64(pngData) console.log( "=---" , base64) } }) wx.setStorageSync( 'addImg' , tempFilePaths[0]) that.setData({ addImg: tempFilePaths[0] }) }) } }) |