HTML 5 Canvas - Dynamically include multiple images in canvas
Posted
by
Ron
on Stack Overflow
See other posts from Stack Overflow
or by Ron
Published on 2012-09-26T15:20:35Z
Indexed on
2012/09/26
15:37 UTC
Read the original article
Hit count: 335
I need to include multiple images in a canvas
. I want to load them dynamically via a for-loop
.
I tried a lot but in the best case only the last image is displayed. I check this tread but I still get only the last image.
For explanation, here's my latest code(basically the one from the other post):
for (var i = 0; i <= max; i++)
{
thisWidth = 250;
thisHeight = 0;
imgSrc = "photo_"+i+".jpg";
letterImg = new Image();
letterImg.onload = function() {
context.drawImage(letterImg,thisWidth*i,thisHeight);
}
letterImg.src = imgSrc;
}
Any ideas?
© Stack Overflow or respective owner