Reputation: 9964
Whenever I try to run this, I get a type error in chrome: Code Update
// Get the drawing canvas
canvas = $('#drawing');
context = canvas[0].getContext('2d');
function resizeCanvas() {
canvas.attr({'width' : $(window).width()});
canvas.attr({'height' : $(window).height() - 158});
var dataURL = canvas[0].toDataURL('image/png');
context.drawImage(dataURL, 0, 0);
}
$(window).resize(function() {
resizeCanvas();
}); resizeCanvas();
// Various event handlers after this.
Why!?
Upvotes: 0
Views: 639
Reputation: 140210
drawImage
takes an image or a canvas reference, you are passing it a string.
For instance:
var a = document.createElement("canvas");
a.getContext("2d").drawImage("asdasdasd", 0, 0 )
//TypeError: Type error
You could try:
context.drawImage(canvas[0], 0, 0);
Or
var image = new Image();
image.src = dataURL;
context.drawImage( image, 0, 0 );
Upvotes: 1
Reputation: 91299
Your code seems fine. Check the following:
canvas
element with id drawing
;canvas
.Upvotes: 1