[英]HTML/CSS: Background Image from raw image data, not url
i get the raw image data of a png-image from a webserver, and want to use it as the background image of a div-element. 我从网络服务器获取png图像的原始图像数据,并希望将其用作div元素的背景图像。 is this possible without saving the data as an image-file first?
是否可以先不将数据另存为图像文件?
document.getElementById('e').src = 'data:image/png;base64,ton_of_crap';
In that Wikipedia article, there is code for PHP and Python that outputs base-64 encoded images. 在该Wikipedia文章中,有用于PHP和Python的代码,可输出基于64位编码的图像。 You can just shove that into the
url()
of a CSS file (or the src
attribute of a <img />
tag) and it should work. 您可以将其推入CSS文件的
url()
(或<img />
标签的src
属性)中,它应该可以工作。
Have you tried (with jQuery): 您是否尝试过(使用jQuery):
$('#divID').css("background-image", "url(/myimage.png)");
From Switching a DIV background image with jQuery 从使用jQuery切换DIV背景图像开始
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.