tags:

views:

67

answers:

2

Hello everyone,

Is there a way to save a canvas element's content to data such as binary? I'm looking to be able to redraw this data when needed.

Not really sure on how to go about it..

Thanks so much!!

A: 

I suppose you can send the innerHTML of whatever element contains the canvas element back to the server using AJAX and then zip it up server side.

However, this would be grossly inefficient to an alternate method of creating a data-based representation of of the content, and just storing that without all the unnecessary overhead of actual HTML markup.

Mike Sherov
But would this return the drawn data? I'm not sure it would..
It would return the HTML necessary to create the image again on another HTML page. If you're looking for a jpg or something... That's something else.
Mike Sherov
+2  A: 

You should be able to save the image into a variable like so: var imageVar = canvasObject.toDataURL();, and restore it again by calling canvasObject.drawImage(imageVar);

I haven't tested it yet, but the spec says it should work.

SphereCat1
Thanks SphereCat1! toDataUrl() works but i couldn't get .drawImage to work. This gets me in the right direction though. Thanks!