Answer the question
In order to leave comments, you need to log in
How to embed image on canvas NOT only on load?
I have a canvas and I need to use the same image there multiple times. Can I somehow write it to a variable, and then just pass it to ctx.drawImage? How to do it without img.onload?
const image = new Image();
image.src = src;
image.onload = () => {
texture = image;
};
Answer the question
In order to leave comments, you need to log in
With data:URL (RFC 2397).
<img src="data:image/gif;base64,R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0j
vb29t/f3//Ub//ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAAAAALAAAAAAQAA4AAA
Re8L1Ekyky67QZ1hLnjM5UUde0ECwLJoExKcppV0aCcGCmTIHEIUEqjgaORCMxIC6e0Cc
guWw6aFjsVMkkIr7g77ZKPJjPZqIyd7sJAgVGoEGv2xsBxqNgYPj/gAwXEQA7" width="16"
height="14">
const image = new Image();
image.src = strDataURI; // картинка уже в строке
texture = image;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question