I have a canvas. Now i want to make an image of the canvas. This function i already developed. I've got an image with the right src-attribute. But if i want to append this image-element to the html-container, it doesn't works. Nothing happens.
I don't know why. The html-container is available, the image is correct.
Here is some code:
Function to create the picture
function createPicture(canvas, container){
let dataURL = canvas.toDataURL({
width: canvas.width,
height: canvas.height,
left: 0,
top: 0,
format: 'jpeg',
});
let image = new Image();
image.setAttribute("src", dataURL);
container.append(image);
}
Calling this function
createPicture(canvas, $("#test"));
Image in the console:
<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD…">