Draw the image onto the canvas: - Javascript Canvas Reference

Javascript examples for Canvas Reference:drawImage


Draw the image onto the canvas:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<p>Image to use:</p>
<img id="scream" src="http://java2s.com/resources/b.png" alt="The Scream" width="220" height="277">

<canvas id="myCanvas" width="300" height="250" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>

window.onload = function() {//from  ww w.  j a  v a  2s . c o  m
    var c = document.getElementById("myCanvas");
    var ctx = c.getContext("2d");
    var img = document.getElementById("scream");
    ctx.drawImage(img, 90, 130, 50, 60, 10, 10, 50, 60);


Related Tutorials