These forums are currently read-only due to receiving more spam than actual discussion. Sorry.

It is currently Sat Dec 02, 2017 4:14 pm Advanced search

How to display a jpg data in Canvas

Do you think the HTML spec should do something differently? You can discuss spec feedback here, but you should send it to the WHATWG mailing list or file a bug in the W3C bugzilla for it to be considered.

How to display a jpg data in Canvas

Postby yzhou88 » Sun Oct 03, 2010 2:57 am

Hi,
My browser connects to the server through Websocket and get jpg format picture, but how can I display it? can I display it in Canvas or something? Can someone help me?

I that canvas.putImageData can work a little, but how can we use a jpg data?

Thanks
yzhou88
<h6>
 
Posts: 3
Joined: Sun Oct 03, 2010 2:52 am

Postby zcorpan » Mon Oct 04, 2010 9:19 am

Since Websocket only works with strings currently, I take it that you're sending it base64 encoded?

You could put it in <img src="data:image/jpeg;base64,JPEG_DATA_HERE">. If you want to paint it on a canvas, use drawImage(img, 0, 0).
zcorpan
<article>
 
Posts: 807
Joined: Tue Feb 06, 2007 8:29 pm
Location: Sweden

Postby yzhou88 » Mon Oct 04, 2010 5:44 pm

Great!
Thanks for your help!
yzhou88
<h6>
 
Posts: 3
Joined: Sun Oct 03, 2010 2:52 am

Postby JAB Creations » Mon Oct 04, 2010 7:14 pm

Just a friendly heads-up, that method won't work in all browsers, mainly older versions of IE. I'm not sure which do and do not work though hopefully all versions of the browsers you plan to use do.
User avatar
JAB Creations
<aside>
 
Posts: 566
Joined: Tue Mar 13, 2007 4:48 am
Location: Sarasota Florida, USA

Postby yzhou88 » Tue Oct 05, 2010 1:53 pm

It's working. I have tried. In addition, here is an article about it.
http://en.wikipedia.org/wiki/Data_URI_scheme

Thanks again!
yzhou88
<h6>
 
Posts: 3
Joined: Sun Oct 03, 2010 2:52 am


Return to Feedback on the Specs

Who is online

Users browsing this forum: No registered users and 0 guests