【问题标题】:html canvas problems with context.drawImage()context.drawImage() 的 html 画布问题
【发布时间】:2020-05-30 23:38:41
【问题描述】:

我正在使用画布,我正在尝试将图像绘制到画布上,但它不起作用。我发现我需要使用 eventListener 但它没有解决它。谁能告诉我怎么了。

const c = document.getElementById("myCanvas");
const ctx = c.getContext("2d");

const groundImg = new Image();
groundImg.src = "ground.png";

groundImg.addEventListener("load", startDraw());

function startDraw() {
    ctx.drawImage(groundImg, 0, 0, c.width, c.height);
}

【问题讨论】:

标签: javascript html canvas drawimage


【解决方案1】:

改变:

groundImg.addEventListener("load", startDraw());

到:

groundImg.addEventListener("load", startDraw);

【讨论】:

    猜你喜欢
    • 2014-11-28
    • 1970-01-01
    • 1970-01-01
    • 2019-12-23
    • 2020-10-19
    • 2014-01-04
    • 2014-09-11
    • 2011-05-31
    • 2014-01-08
    相关资源
    最近更新 更多