+1

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

GOD_OF_CODING

2 Answers

New Answer

+3

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() }

+1

Wowoowowowow worked 💼 you are life saver