Hello everyone,
I've tried to retrieve an image from a websocket server (in .NET) I send the image as bytes then I retrieve it on the client side, the code for retrieving on the client side (using canvas and JavaScript):
var c=document.GetElementById("myCanvas");
var ctx=c.getContext("2d");
ws.onmessage=function(evt)
{
var image=new Image();
image.src=URL.createObjectURL(evt.data);
ctx.drawImage(image,0,0);
}
it perfectly displays the picture on firefox, but at Chrome, it just returning undefined and won't load the image through createObjectURL I'm using Chrome 18.0.1025.162
any idea?
Deprecated. Not for use in new websites.
revokeObjectURL() static method releases an existing object URL which was previously created by calling URL. createObjectURL() . Call this method when you've finished using an object URL to let the browser know not to keep the reference to the file any longer. Note: This feature is available in Web Workers.
From MDN:
This method is prefixed in Chrome and Webkit as
window.webkitURL.createObjectURL()
.
You should test if URL
exists and then use the appropriate object:
(window.URL ? URL : webkitURL).createObjectURL(evt.data);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With