Place an image behind other drawings on Canvas - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Image

Description

Place an image behind other drawings on Canvas

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=( function() {/*from  w w  w.  j a v a 2  s.  com*/
var can = document.getElementById('canvas1');
var ctx = can.getContext('2d');
var img = new Image();
img.onload = function() {
    ctx.drawImage(img, 0, 0);
    ctx.fillRect(50,50,150,150);
}
img.src = 'http://placekitten.com/500/500';
    });

      </script> 
   </head> 
   <body> 
      <canvas id="canvas1" width="500" height="500"></canvas>  
   </body>
</html>

Related Tutorials