THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

HTML Canvas Images


Canvas - Images

To draw an image on a canvas, use the following method:

  • drawImage(image,x,y)

Example

The Scream

JavaScript:

window.onload = function() {
    var canvas = document.getElementById("myCanvas");
    var ctx = canvas.getContext("2d");
    var img = document.getElementById("scream");
    ctx.drawImage(img, 10, 10);
};
Try it Yourself »
Note You cannot draw the image before the image has loaded. Call the function from window.onload().