你还在找在小程序成如何将图片转base64存储起来并显示嘛,在这里呢,来瞧瞧。
使用方法
js文件
let $this = this;
request({
 url:'https://www.dounine.com/hello.jpg',
 method:'GET',
 responseType: 'arraybuffer',
 success:function(res){
 let base64 = wx.arrayBufferToBase64(res);
 $this.data.userImageBase64 = 'data:image/jpg;base64,' + base64;;
 }
}); 
wxml文件
<image src='{{userImageBase64}}' style='width:90rpx;height:90rpx;' />
PS:小程序本地图片转base64最简单方法
- wx.chooseImage:得到图片地址
- wx.getFileSystemManager:创建文件管理类
- readFileSync:读取本地文件,直接得到base64
 wx.chooseImage({
 success: function(res) {
 console.log(wx.getFileSystemManager().readFileSync(res.tempFilePaths[0], "base64"))
 },
 })
附官方api: https://developers.weixin.qq.com/miniprogram/dev/api/file/wx.getFileSystemManager.html?search-key=getFileSystemManager
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。