I am trying to implement a cancel function for a canvas. Basically, people can draw on canvas, and then restore it to the state it used to be. This is a theory. I save the current imageData every time I call the draw function. It is stored in the eD (namespace) .history array. Drawing works great even if I manipulate the image. Here's my draw-function (cD is also a namespace):
editorClass.prototype.draw = function(){ eD.history.push(cD.imageData); cD.context.putImageData(cD.imageData, 0, 0); }
Now, if I try to undo my changes that I made between them, I use the undo function, which looks like this:
editorClass.prototype.undo = function(){ var temp = eD.history.pop(); cD.context.createImageData(cD.width,cD.height);
As mentioned above, this will not work. The canvas that I work with is created after the user loads the site. cD.imageData is taken from this function:
editorClass.prototype.getPixels = function(){ cD.imageData = cD.context.getImageData(0, 0, cD.width, cD.height);
Both namespaces are visible if necessary. Since I'm pretty new to canvas, this might be a simple question, so if you have any improvements: I'm empty bucked, fill me in;)
thanks
source share