HTML Canvas Image Load

Description

HTML Canvas Image Load

View in separate window

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Load Image</title>
  </head>/*from  w w w  . ja  va 2  s . c o m*/
  <body>
    <canvas id="canvas" width="400" height="400"></canvas>
    
    <script>
    window.onload = function () {
      var canvas = document.getElementById('canvas'),
          context = canvas.getContext('2d'),
          image = new Image();

      image.src = "image1.png";
      image.onload = function() {
        context.drawImage(image, 0, 0);
      };
    };
    </script>
  </body>
</html>



PreviousNext

Related