I have a html code as follow:
<canvas id="canvas1" width="200" height="200"></canvas>
and a javaScript code as follow:
var can = document.getElementById('canvas1');
var ctx = can.getContext('2d');
var src="https://vignette2.wikia.nocookie.net/mint524/images/d/d7/Sky.jpg/revision/latest?cb=20160706152654.jpg"
var image = new Image();
image.onload = function(){
ctx.drawImage(image,0,0,50,50);
}
ctx.fillRect(50,50,50,50);
image.src = src
var img = new Image();
img.src = can.toDataURL();
document.body.appendChild(img);
I want to convert canvas
to a img
element, but I found I can not append the image in canvas to the img element. Detialed code is in here.
Can anyone give some advises?