Frage

I have a canvas on one page that is built using fabricjs can i send that canvas to another page so that it retains all its objects as it is with all their properties and attributes to be same aswell.

War es hilfreich?

Lösung

Sure you can, just export your canvas to JSON

var canvas = new fabric.Canvas('c');
data = JSON.stringify(canvas)

Now you can send that data using a post request or store it in a database or whatever you want.

canvas.loadFromJSON(data, canvas.renderAll.bind(canvas));

Example: http://jsfiddle.net/P9cEf/3/

The example uses two canvases one page, but the concept is the same.

Edit: To download the image client side

var canvas1 = document.getElementById("c");
var image = canvas1.toDataURL("image/png").replace("image/png", "image/octet-stream");
window.location.href = image;
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top