原生js,文件流變成圖片以前寫過,今天在微信小程序中也遇到類似的問題
// 形參 arrayBuffer 傳入的就是后端返回的文件流
arrayBufferToImage: function (arrayBuffer) {
const fileSystem = wx.getFileSystemManager(); const filePath = wx.env.USER_DATA_PATH + '/tempImage' + Date.now() + '.png'; // 臨時文件路徑 // 寫入文件 fileSystem.writeFile({ filePath: filePath, data: arrayBuffer, // 直接使用字節(jié)流 一定要寫 encoding: 'binary', success: (res) => { this.setData({ imagePath: filePath }); wx.setStorageSync('imagePath', filePath) }, fail: (err) => { console.error('文件保存失敗:', err); } }); },
處理后會變成這種

在頁面上使用
<image class="qrcode {{isShow?'':'qrcode_small'}}" src="{{imagePath}}" mode="widthFix"></image>
浙公網(wǎng)安備 33010602011771號