這篇文章給大家分享的是有關(guān)微信小程序圖片地扯轉(zhuǎn)base64的示例分析的內(nèi)容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧。
使用方法
js文件
let $this = this; request({ url:'/file/tupian/20230213/hello.jpg', method:'GET', responseType: 'arraybuffer', success:function(res){ let base64 = wx.arrayBufferToBase64(res); $this.data.userImageBase64 = 'data:image/jpg;base64,' + base64;; } });
wxml文件
PS:小程序本地圖片轉(zhuǎn)base64最簡(jiǎn)單方法
wx.chooseImage:得到圖片地址
wx.getFileSystemManager:創(chuàng)建文件管理類
readFileSync:讀取本地文件,直接得到base64
wx.chooseImage({ success: function(res) { console.log(wx.getFileSystemManager().readFileSync(res.tempFilePaths[0], "base64")) }, })
感謝各位的閱讀!關(guān)于“微信小程序圖片地扯轉(zhuǎn)base64的示例分析”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!