admin管理员组文章数量:1400329
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. is this possible without saving the data as an image-file first?
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. is this possible without saving the data as an image-file first?
Share Improve this question asked Jun 14, 2012 at 5:33 user1448982user1448982 1,2703 gold badges13 silver badges22 bronze badges2 Answers
Reset to default 5Use a data URI:
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. You can just shove that into the url()
of a CSS file (or the src
attribute of a <img />
tag) and it should work.
Have you tried (with jQuery):
$('#divID').css("background-image", "url(/myimage.png)");
From Switching a DIV background image with jQuery
本文标签: javascriptHTMLCSS Background Image from raw image datanot urlStack Overflow
版权声明:本文标题:javascript - HTMLCSS: Background Image from raw image data, not url - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744256958a2597527.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论