Languages
[Edit]
EN

JavaScript - draw image on canvas element

3 points
Created by:
Hayley-Mooney
677

Quick solution:

 

Using JavaScript canvas element context it is possible to draw image in following way.

1. drawImage() method example

Edit

With this approach HTMLImageElement type handle is necessary.

Avaialble approaches to get element handle are:

  1. with document.querySelector(), docuemnt.getElementById() or other similar method,
  2. with document.createElement('img') execution,
  3. with new Image() execution.

Following example shows how to use new Image() approach:

Used resources:

Used image with canvas.
Used image with canvas.
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

JavaScript - HTML5 canvas tutorial

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join