简体   繁体   English

在javascript中显示来自blob的图像

[英]Show image from blob in javascript

i am using localstorage html5. 我正在使用localstorage html5。 first i am saving mysql db values into localstorage then i am fetching where i want.its fine. 首先,我将mysql数据库值保存到localstorage然后我提取我想要的地方。很好。 i want to save images (like images of products) into localstorage and then want to show them where i want, 我想将图像(如产品图像)保存到本地存储中,然后想要将它们显示在我想要的位置,

i did an experiment as I saved images in blob in mysql, and i am able to fetch and show them using php but i dont want to use php here,the purpose is of offline working.i am unable to show image via javascript 我做了一个实验,因为我在blob中保存图像在mysql中,我能够使用PHP获取和显示它们但我不想在这里使用PHP,目的是离线working.i无法通过javascript显示图像

any one can help me?? 任何人都可以帮助我? There might be two ways, 可能有两种方式,

one is can we encript image (i have to path to image)in some sort of string in javascript and then can i show that on anywhere. 一个是我们可以用javascript中的某种字符串来识别图像(我必须路径到图像),然后我可以在任何地方显示它。

Second way.. as i said i saved it in blob can i use javascript to just show image from blob. 第二种方式..正如我说我保存在blob中我可以使用javascript来显示blob中的图像。 by the way i can fectch value from database easily.now the only thing is to save that value into javascript and show its image where i want. 顺便说一句,我可以很容易地从数据库中获取价值。现在唯一的办法就是将这个价值保存到javascript中并将其图像显示在我想要的位置。

I will wait for reply thank you:) 我会等待回复谢谢:)

You can also use URL.createObjectURL(blob) specified here and for cross-browser compatibility, check this out: 您还可以使用此处指定的URL.createObjectURL(blob)以及跨浏览器兼容性,请查看以下内容

var uri = URL.createObjectURL(blob);
var img = new Image();

img.src = uri;
document.body.appendChild(img);

You can use a Data URI scheme for the images: 您可以为图像使用Data URI scheme

<img src="data:image/png;base64,
iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGP
C/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IA
AAAddEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1J
REFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1exdlYvBBeZ7jq
ch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0
vr4MkhoXe0rZigAAAABJRU5ErkJggg==" alt="Red dot" />

This requires you to encode the data and there is a limit to the size in some browsers (32kb in IE, for example). 这需要您对数据进行编码,并且某些浏览器的大小有限(例如,IE中为32kb)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM