Answer the question
In order to leave comments, you need to log in
How to draw elements on canvas?
How to draw elements on canvas? The text from the div block is rendered. And how to display a tag in a place with text?
If I insert a tag it is not drawn on the canvas.
So there is only text
let canvas = document.getElementById("canvas");
let ctx = canvas.getContext("2d");
let data = "data:image/svg+xml,"+
"<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'>" +
"<foreignObject width='100%' height='100%' >" +
"<div xmlns='http://www.w3.org/1999/xhtml'>Текст</div>" +
"</foreignObject>" +
"</svg>";
let img = new Image();
img.src = data;
img.onload = function() { ctx.drawImage(img, 0, 0); }
console.info(data)
let canvas = document.getElementById("canvas");
let ctx = canvas.getContext("2d");
let data = "data:image/svg+xml,"+
"<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'>" +
"<foreignObject width='100%' height='100%' >" +
"<div xmlns='http://www.w3.org/1999/xhtml'>Текст</div><img src='coin.jpg'>" +
"</foreignObject>" +
"</svg>";
let img = new Image();
img.src = data;
img.onload = function() { ctx.drawImage(img, 0, 0); }
console.info(data)
Answer the question
In order to leave comments, you need to log in
The problem is src='coin.jpg', the image does not know how to load external resources, use the same data url for the embedded image
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question