javascript - Dynamically add <img> elements to canvas -
i'm trying make react app. have div element bunch of images that's added dynamically. after clicking button want add each image canvas. i'm having trouble adding canvas because keeps giving me error because i'm not loading images before using drawimage(). i'm confused how works because image on dom already, have preload or something?
this have right now, doesn't give me error doesn't want because experimenting. @ first had loop src of every , threw error , though needed object. made object literal , pushed src of every there , canvas, gave same error. have image constructor experiment with, don't know it.
captureimage(){ let canvas = document.queryselector("#canvas") let ctx = canvas.getcontext("2d") let imgdiv = document.queryselector(".images") let imgel = document.getelementsbytagname("img") let imgobj = new image imgobj.onload = function(){ ctx.drawimage(imgobj.images[n],0,0) } if (imgel){ (var n = 0;n < imgel.length;n++){ imgobj[n] = imgel[n].src console.log(imgobj.images) } } }
the function called onclick. i'm confused. don't understand place things.
Comments
Post a Comment