我如何使用JS将图像显示为Blob对象 [英] How I display as image a blob object with JS
本文介绍了我如何使用JS将图像显示为Blob对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在控制台中登录该函数时,该函数将返回一个blob对象:
My function returns a blob object when I log it in my console:
Blob(623853) {name: "profile.jpg", size: 623853, type: "image/jpeg"}
我想用JavaScript向用户显示此图像,怎么办?
I want to display this image to the user with JavaScript, how can I do it?
推荐答案
您可以使用 URL.createObjectURL 生成一个Blob URL并将其设置为图像源.
You can use URL.createObjectURL to generate a blob URL and set it as the image source.
const blobUrl = URL.createObjectURL(blob) // blob is the Blob object
image.src = blobUrl // image is the image element from the DOM
这篇关于我如何使用JS将图像显示为Blob对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文