+ 3

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>

5th Apr 2020, 7:03 AM
KRiShNa P
KRiShNa P - avatar
2 Réponses
+ 4
Wowoowowowow worked 💼 you are life saver
5th Apr 2020, 7:25 AM
KRiShNa P
KRiShNa P - avatar
+ 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() }
5th Apr 2020, 7:10 AM
durian
durian - avatar