我只是尝试使用以下代码绘制图像:
(function() {
var canvas = document.getElementById('canvas'),
context = canvas.getContext('2d');
// resize the canvas to fill browser window dynamically
window.addEventListener('resize', resizeCanvas, false);
function resizeCanvas() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
drawStuff();
}
resizeCanvas();
var imageObj = new Image();
imageObj.onload = function() {
drawStuff();
};
imageObj.src = 'http://www.html5canvastutorials.com/demos/assets/darth-vader.jpg';
function drawStuff() {
context.drawImage(imageObj, 69, 50);
}
})();
但我得到了错误
未捕获的 TypeError:类型错误
我哪里错了?