How to display Base64 images in HTML?

后端 未结 11 2348
一整个雨季
一整个雨季 2020-11-21 06:10

I\'m having trouble displaying a Base64 image inline.

Can someone point me in the right direction?



  
         


        
11条回答
  •  梦谈多话
    2020-11-21 07:13

    Try this one too:

    let base64="iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==";
    let buffer=Uint8Array.from(atob(base64), c => c.charCodeAt(0));
    let blob=new Blob([buffer], { type: "image/gif" });
    let url=URL.createObjectURL(blob);
    let img=document.createElement("img");
    img.src=url;
    document.body.appendChild(img);
    

    Not recommended for production as it is only compatible with modern browsers.

提交回复
热议问题