gpt4 book ai didi

Javascript 在 Canvas 上循环创建图像

转载 作者:行者123 更新时间:2023-11-30 20:52:08 28 4
gpt4 key购买 nike

<分区>

我正在循环浏览我的图像并尝试将所有图像都放在我的 Canvas 中,但出现此错误:

我的 HTML:

<div class="container-fluid">

<canvas id="signature-canvas" class="signature-canvas"></canvas>

</div>

signatures.js:121 Uncaught TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(CSSImageValue or HTMLImageElement or SVGImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap or OffscreenCanvas)' at Image.images.(anonymous function).onload (http://localhost/app/public/js/signatures.js:121:25)

我的javascript

var canvasModule = {

elements: {
canvas: document.getElementById('signature-canvas')
},

render: function () {
this.createImageOnCanvas();
},

getCanvasContext: function () {
return this.elements.canvas.getContext('2d');
},

getCanvasWidth: function () {
return this.elements.canvas.width;
},

getCanvasHeight: function () {
return this.elements.canvas.height;
},

createImageOnCanvas: function () {

var itemWidth = this.getCanvasWidth() / 7;
var itemHeight = this.getCanvasHeight() / 3;

var u = 0;
var context = this.getCanvasContext();
var images = [];
var imagesWidth = [];
var imagesHeight = [];

for (var i = 1; i < 8; i++) {
images[i] = new Image();

images[i].src = 'images/sample/1'+i+'.png';

imagesWidth[i] = images[i].width;
imagesHeight[i] = images[i].height;

images[i].onload = function () {
context.drawImage(images[i], u, 0, itemWidth, itemHeight);
}

u = u + itemWidth;
}

}

}


$(document).ready(canvasModule.render());

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