3

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

4

2 回答 2

9

You should be able to create the element with JavaScript:

var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
于 2013-04-23T23:35:55.600 回答
4

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.

于 2013-04-23T23:35:49.533 回答