javascript - 将 blob 响应视为角度图像
问题描述
我正在尝试从请求中获取 blob 响应,然后从该 blob 生成 URL 并将此 URL 设置为图像的源。
但是图像没有加载。
这是我的 HTML:
<img src="{{previewSignsrc}}" alt="Sign Thumbnail">
这是我的.ts
文件:
this.signModalDataService.getPreviewSignature({'name': this.SignatureName, 'font_type': 0});
this.signModalDataService.previewSignature
.subscribe((res) => {
console.log(res);
let blob = new Blob([res['_body']], {type: 'image/png'});
this.previewSignsrc = URL.createObjectURL(blob);
this.showPreviewSign = true;
});
我使用相同的方法进行设置url
,ng2-pdfviewer
并且效果很好。
解决方案
您可以像此代码一样显示图像
this.config.getData()
.subscribe((blob : any) => {
let objectURL = URL.createObjectURL(blob);
this.image = this.sanitizer.bypassSecurityTrustUrl(objectURL);
});
如果您的数据是 base64 显示这样
this.config.getData()
.subscribe((baseImage : any) => {
let objectURL = 'data:image/jpeg;base64,' + baseImage.image;
this.thumbnail = this.sanitizer.bypassSecurityTrustUrl(objectURL);
});
推荐阅读
- shopify - 光滑的滑块在移动 safari 浏览器中不起作用(shopify 商店)
- text-to-speech - 有什么我应该添加到我的代码中来改进我的代码的吗
- awk - 仅在特定列之间更改分隔符
- jquery - 未使用 laravel 8 将数据插入数据库
- python - 如何发送请愿书多线程 Python / Django
- python - 对象没有被存储和从多处理队列中提取
- ios - 从 iOS 应用程序中访问使用 os_log 捕获的日志
- python - TypeError(python tkinter 条目)
- sql - 带有 JOIN 的 Oracle SQL 触发器
- r - quantstrat 中 add.indicator() 中的参数