You should check if the image is uploaded. If not, then listen for the download event.
questionbg.src = "./resources/imageaudiovideoquestionbg.png"; if (questionbg.complete) { context.drawImage(questionbg, 0, 0); } else { questionbg.onload = function () { context.drawImage(questionbg, 0, 0); }; }
MDN (Mozilla Doc, an excellent source of btw) offers:
function draw() { var ctx = document.getElementById('canvas').getContext('2d'); var img = new Image(); img.onload = function(){ ctx.drawImage(img,0,0); ctx.beginPath(); ctx.moveTo(30,96); ctx.lineTo(70,66); ctx.lineTo(103,76); ctx.lineTo(170,15); ctx.stroke(); }; img.src = '/files/4531/backdrop.png'; }
Obviously, you do not want to apply a stroke or fill. However, the idea is the same.
source share