Reputation: 36299
I want to create a canvas object in memory, and not require a HTML <canvas>
tag. Is this possible?
With this code:
var canvas = new Canvas();
var ctx = canvas.getContext('2d');
I get this error message: Uncaught ReferenceError: Canvas is not defined
Upvotes: 4
Views: 17598
Reputation: 2011
You should be able to create the element with JavaScript:
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
Upvotes: 10
Reputation: 664297
Use document.createElement("canvas")
instead. There is no Canvas
constructor for canvases, as you know it from Image
for images or Option
for options - those are the sole exceptions.
Upvotes: 4