Webservice returns binary representation of an image, javascript
How can I take that binary string representation and turn it into an image using javasc开发者_如何转开发ript. I am using jquery....
Do I need to do this using a server side script?
Thanks!
If you're talking about something like a base64-encoded image, you just need to use the data URI scheme:
data:[<MIME-type>][;charset=<encoding>][;base64],<data>
For example, if the image is encoded in this string:
"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD///+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4Ug9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC"
then you create this <img>
element:
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD///+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4Ug9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC" alt="Red dot" />
http://jsfiddle.net/mattball/s2mNa/
精彩评论