I am trying to create 3 canvas.
However, I couldn't able to draw it. Is there anything I did wrong?
HTML code
<body>
<img id="image1" src="http://www.gravatar.com/avatar/0e39d18b89822d1d9871e0d1bc839d06?s=128&d=identicon&r=PG">
<canvas id="myCanvas"></canvas>
<img id="image2" src="http://nuclearpixel.com/content/icons/2010-02-09_stellar_icons_from_space_from_2005/earth_128.png">
<canvas id="myCanvas2"></canvas>
<canvas id="myCanvas3"></canvas>
</body>
Javescript
var c = document.getElementById("myCanvas");
var a = c.toDataURL();
alert(a);
var myCanvas = document.getElementById('myCanvas3');
var ctx = myCanvas.getContext('2d');
var img = new Image;
img.src = a;
ctx.drawImage(img, 20, 20);
youre missing the onload
event of the image:
var image = new Image
image.src = "URL or DataURL"
image.onload = function(){
ctx.drawImage(image)
}
working fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With