Usage

To draw an image onto the HTML5 Canvas, we can use the drawImage() method which requires an image object and a destination point. The destination point is relative to the top left corner of the image. The drawImage() method requires an image object. In our JavaScript block, we must create an image and once it is loaded, we draw the image onto the HTML5 canvas.

Syntax

Draw the image onto the canvas. Draw the image on the canvas, and specify the width and height of the image. Crop the image and draw the cropped portion on the canvas.

Examples

The first example is the most basic one where the image is simply drawn on the canvas element. The second example will draw the image according to the dimensions provided. The third example crops the image and draws the results. Draw the image on the canvas, and specify width and height of the image. Crop the image and draw the cropped portion on the canvas.