Draw image from image elements
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Embed Image</title> <style>canvas{border:1px solid red;}</style> <style> #picture { //from www . j ava2s.c o m display: none; } </style> </head> <body> <canvas id="canvas" width="400" height="400"></canvas> <img id="picture" src="http://java2s.com/style/demo/jet.png"> <script> window.onload = function () { let canvas = document.getElementById('canvas'), context = canvas.getContext('2d'), image = document.getElementById('picture'); context.drawImage(image, 0, 0); }; </script> </body> </html>