我正在尝试将字节数组绑定到角度的图像标签。我知道字节数组是正确的,因为我可以下载它并从我的 API 中查看它。
我创建了这样的图像:
<img [src]="src" />
然后在我的代码中,我像这样清理字节数组:
this.src = this.sanitizer.bypassSecurityTrustResourceUrl(`data:image/svg+xml,${this.location.qrCode}`);
在我的控制台中,我可以看到:
但是图像没有显示。我究竟做错了什么?
我尝试了其他一些事情:
const reader = new FileReader();
reader.onload = (e) => (this.src = this.sanitizer.bypassSecurityTrustResourceUrl(e.target.result.toString()));
reader.readAsDataURL(new Blob([this.location.qrCode]));
和
this.src = this.sanitizer.bypassSecurityTrustResourceUrl(`data:image/svg+xml;base64,${this.test}`);
和
this.src= btoa(this.location.qrCode);
和
const reader = new FileReader();
reader.onload = (e) => (this.src = e.target.result);
reader.readAsDataURL(new Blob([this.location.qrCode]));
他们都没有工作:(