鍍金池/ 問(wèn)答/HTML5  HTML/ 微信小程序如何把上傳照片的臨時(shí)路徑轉(zhuǎn)變成照片的base64格式?

微信小程序如何把上傳照片的臨時(shí)路徑轉(zhuǎn)變成照片的base64格式?

fff: function () {
    var that = this;
    const ctx = wx.createCanvasContext('myCanvas')
    wx.chooseImage({
      success: function (res) {
        ctx.drawImage(res.tempFilePaths[0], 0, 0, 150, 100)
        ctx.draw(false, () => {
         wx.canvasGetImageData({
            canvasId: 'myCanvas',
            x: 0,
            y: 0,
            width: 100,
            height: 100,
            success(res) {
              console.log(res.width) // 100
              console.log(res.height) // 100
              console.log(res.data instanceof Uint8ClampedArray) // true
              console.log(res.data) // 100 * 100 * 4
              let base64 = wx.arrayBufferToBase64(res.data);
              //console.log(base64)
              that.data.userImageBase64 = 'data:image/jpg;base64,' + base64;
              console.log(that.data.userImageBase64)
            }
          })
        })
           }
    })
  },

小程序開(kāi)發(fā)后臺(tái)顯示如圖
圖片描述

但是這最后一大竄碼轉(zhuǎn)換不出正確的圖片,求大神指導(dǎo)。。。

回答
編輯回答
厭遇

祝你好運(yùn)

如果只是為了上傳圖片建議二進(jìn)制上傳,還省體積

2018年8月11日 15:57
編輯回答
伴謊

這個(gè)問(wèn)題解決了嗎!?。。。?/p>

2017年12月24日 15:03