Answer the question
In order to leave comments, you need to log in
Why is the image not being added to the canvas?
Why is the image not being added to the canvas?
Here is the code:
<!DOCTYPE html>
<html>
<head>
<title>canvas</title>
<meta charset="utf-8">
</head>
<body>
<canvas id='draw' width='570' height='330' style='border:1px solid'></canvas>
<script>
var canvas=document.getElementById("draw")
var x=canvas.getContext("2d");
var img = new Image();
img.src = '/home/sergei/www/canvas/12.png';
x.drawImage(img,10,10);
</script>
</body>
</html>
Answer the question
In order to leave comments, you need to log in
It doesn't work in your case due to security reasons built into browsers, it requires a server to work.
The picture has not loaded yet, and you are already trying to draw it
Alexey Yarkov wrote the correct version of the code in one of the comments
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question