I’am new to canvas. I was using the following code to insert a image in canvas from another image. When I try to create image from a div using the code
<!DOCTYPE html><html>
<head>
<title>test</title>
<script type="text/javascript">
var colour="#ccc",bgcolour="#fff";
function paint(hhh){
canvas = document.getElementById('canvas');
ctx = canvas.getContext('2d');
var img=document.getElementById('mine');
ctx.drawImage(img,0,0);
}
</script>
</head>
<body onload="paint('scribble');" >
<canvas id="canvas" style="border:solid 1px;" width="400" height="400">g</canvas> <div id="mine">canvas</div>
</body>
</html>
It is not working.
My question is how to draw a image from div instead of another image?
The only images you may draw with drawImage on a Canvas, are those declared in “src” attributes of a image object. Specifications may be found here.
I don’t know any method to put the contents of a div tag inside of an image object and I don’t think this is really an easy thing to do. You should think about alternatives…