我想在画布上获取图像及其 x,y,因为它是每隔一定时间在画布上随机位置绘制的。 我有图片来源,不知道是否有帮助 谢谢你
我尝试使用drawImage函数,但我实际上并不熟悉它,这对我来说真的很难
我建议您查看本教程。基本上,您可以添加这样的图像:
const c = document.getElementById("canvas");
const ctx = c.getContext("2d");
const img = new Image();
img.src = "https://i.ibb.co/nQ7cRPv/image.jpg"; // image url
img.onload = function() {
ctx.drawImage(img, 10, 10, 200, 100); // 10,10 is the position, 200,100 is the size
};
<canvas id="canvas" width="250" height="300" style="border:1px solid grey"></canvas>
希望这有帮助!