+ 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>
2 Respuestas
+ 4
Wowoowowowow worked 💼 you are life saver
+ 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()
}