javascript - HTMLCSS: Background Image from raw image data, not url - Stack Overflow

i get the raw image data of a png-image from a webserver, and want to use it as the background image of

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 badges
Add a ment  | 

2 Answers 2

Reset to default 5

Use 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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744256958a4565445.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信