gpt4 book ai didi

javascript - Canvas 图像绘制不起作用

转载 作者:行者123 更新时间:2023-11-30 15:52:58 24 4
gpt4 key购买 nike

<分区>

我正在尝试在 Javascript 窗口加载后使用 Canvas 绘制图像,但我只能获得图像的一部分而无法获得完整图像。请帮助我。

 <!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<script>

window.onload = function() {
drawEx1();
}

var image1 = null;

function drawEx1() {
image1 = new Image();
image1.src =
"file:///C:/Users/Documents/project%20trails/app/i.jpg";
image1.addEventListener('load', drawImage1);
}

function drawImage1() {
var canvas = document.getElementById("canvas1");
var context = canvas.getContext("2d");

context.drawImage(image1, 10, 10);
}

</script>

</head>
<body >
<div >

<input type="button" id="btn" value="submit" />
<canvas id="canvas1"></canvas>
</div>
</body>
</html>

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com