Please help me my browser not showing local image and they are in same folder

<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <canvas></canvas> <script> var canvas = document.querySelector("canvas"); var c = canvas.getContext('2d'); canvas.height = window.innerHeight; canvas.width = window.innerWidth; var boy = new Image(); boy.src = "boy.png"; function draw(){ c. drawImage(boy,0,0); } draw(); </script> </body> </html>

4/5/2020 7:03:29 AM


2 Answers

New Answer


u should wait for the img to be loaded to draw the image into the cnvas you can call the draw function after the img loaded u can do this boy.onload = () => { draw() }


Wowoowowowow worked 💼 you are life saver