Hi everyone,
I'm trying to add an image to a HTML canvas, just trying this out and pulling it from Wikipedia but I can't for the life of me get it to work. Has anyone got any suggestions why this might be? Code below, thanks in advance!
I'm trying to add an image to a HTML canvas, just trying this out and pulling it from Wikipedia but I can't for the life of me get it to work. Has anyone got any suggestions why this might be? Code below, thanks in advance!
HTML:
<html>
<canvas id="gameCanvas" width="800" height="600">
</canvas>
<script>
var canvas;
var canvasContext;
window.onload = function() {
canvas = document.getElementById('gameCanvas');
canvasContext = canvas.getContext('2d');
canvasContext.fillStyle = 'black';
canvasContext.fillRect(0,0,canvas.width, canvas.height)
}
var image = new Image();
image.src = 'https://upload.wikimedia.org/wikipedia/commons/4/4c/Catopsbaatar.jpg';
ctx.drawImage(image, 0, 0, 40, 40);
</script>
</html>
Last edited by a moderator: