HTML5 Game - Image Scaling with Canvas

Description

Image Scaling with Canvas

Demo

ResultView the demo in separate window

<!DOCTYPE html> 
<html> 
    <head> 
        <title>Canvas Demo</title> 
        <style> 
canvas { //from w w  w. java 2  s.  co  m
  border: 1px solid #000; 
} 
        </style> 
    </head> 
    <body> 
      <canvas id="myCanvas" width="200" height="200">Did You Know: Every time 
        you use a browser that doesn't support HTML5
      </canvas> 
      <script> 
// Get the context we will be using for drawing. 
let myCanvas = document.getElementById('myCanvas'); 
let myContext = myCanvas.getContext('2d'); 
  
// Create a new image element and fill it with a kitten. 
let myImage = new Image(); 
myImage.src = 'http://www.java2s.com/style/download.png'; 
  
// We can't do anything until the image has successfully loaded. 
myImage.onload = function() { 
  myContext.drawImage(myImage, 25, 25, 50, 150); 
}; 
      </script> 
    </body> 
</html>

Related Topic