下载https://github.com/Pudon/weapp-qrcode-base64
const imgData = QRCode.drawImg('二维码信息', {
typeNumber: 4,
errorCorrectLevel: 'M',
size: 500
})
this.qrcodePath = imgData
const fsm = wx.getFileSystemManager();
const FILE_BASE_NAME = 'tmp_base64src';
//写文件时去掉 base64 的头信息否则绘制不出来
const [, format, bodyData] = /data:image\/(\w+);base64,(.*)/.exec(imgData) || [];
const filePath = `${wx.env.USER_DATA_PATH}/${FILE_BASE_NAME}.${format}`;
const buffer = wx.base64ToArrayBuffer(bodyData);
fsm.writeFile({
filePath,
data: buffer,
encoding: 'binary',
success:() => {
console.log(filePath);
const ctx = uni.createCanvasContext('customCanvas')
ctx.drawImage(filePath, 180*rpx, 200*rpx, 140* rpx, 140* rpx)
}
});
网友评论