javascript - How to display binary data as image - extjs 4 -
javascript - How to display binary data as image - extjs 4 -
here binary valid .jpeg image. http://pastebin.ca/raw/2314500
i have tried utilize python save binary info image.
how can convert info viewable .jpeg image extjs 4?
i tried this, doesn't work.
data:image/jpeg;base64,+ binary info
need convert in base64.
js have btoa() function it.
for example:
var img = document.createelement('img'); img.src = 'data:image/jpeg;base64,' + btoa('your-binary-data'); document.body.appendchild(img);
but think binary info in pastebin invalid - jpeg info must ended on 'ffd9'.
update:
need write simple hex base64 converter:
function hextobase64(str) { homecoming btoa(string.fromcharcode.apply(null, str.replace(/\r|\n/g, "").replace(/([\da-fa-f]{2}) ?/g, "0x$1 ").replace(/ +$/, "").split(" "))); }
and utilize it:
img.src = 'data:image/jpeg;base64,' + hextobase64('your-binary-data');
see working illustration hex info on jsfiddle
javascript ajax extjs extjs4
Comments
Post a Comment