在javascript中显示来自blob的图像 [英] Show image from blob in javascript

查看:84
本文介绍了在javascript中显示来自blob的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用localstorage html5。首先,我将mysql数据库值保存到localstorage然后我提取我想要的地方。很好。我想将图像(如产品图像)保存到本地存储中,然后想要显示它我想要的地方,

i am using localstorage html5. first i am saving mysql db values into localstorage then i am fetching where i want.its fine. i want to save images (like images of products) into localstorage and then want to show them where i want,

我做了一个实验,因为我在mysql中保存了blob中的图像,我能够使用PHP获取和显示它们,但我不想在这里使用PHP,目的是离线working.i我无法通过javascript显示图像

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

任何人都可以帮助我?
可能有两种方式,

any one can help me?? There might be two ways,

一个是我们可以在javascript中的某种字符串中输入图像(我必须路径到图像)然后我可以显示在任何地方。

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.

第二种方式..
因为我说我保存在blob中我可以使用javascript来显示来自blob的图像。顺便说一句,我可以很容易地从数据库中获取价值。现在唯一的办法就是将这个值保存到javascript中并在我想要的地方显示它的图像。

Second way.. as i said i saved it in blob can i use javascript to just show image from 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.

我会等待回复谢谢:)

推荐答案

您还可以使用 URL.createObjectURL(blob)指定此处并且为了跨浏览器兼容性,请检查这个

You can also use URL.createObjectURL(blob) specified here and for cross-browser compatibility, check this out:

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

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

这篇关于在javascript中显示来自blob的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆