怎么转的啊?我这怎么转都是一片空白啊???
小程序上传的图片怎么先转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][代码][代码] [代码][代码]})[代码][代码] [代码] [代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码]
2018-10-16