0
HTML5 캔버스에 이미지를 배치하고 싶습니다. 몇 가지 샘플 코드를 찾았지만 이미지가 실제로 2 번만로드되었습니다. JavaScript 또는 CSS로 이미지 중 하나를 숨길 수는 있지만 이미지를 한 번만로드해야하는 방식을 찾고 있습니다. .html/javascript canvas drawImage 2 회로드하지 않고
<!DOCTYPE html>
<html>
<body>
<img id="img" src="img.png" width="150px" height="150px">
<canvas id="canvas" width="200px" height="200px"></canvas>
<script type="text/javascript">
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var img = document.getElementById("img");
ctx.drawImage(img, 0, 0);
</script>
</body>
</html>
난 단지 이미지가 한 번 표시를 참조하십시오. canvas 요소는 비어 있으며 현재 이미지가 포함되어 있지 않습니다. 내가 놓친 게 있니? – GVashist