i'm trying to insert an image in a canvas but my code does'nt seem to work. i'm getting a canvas with the appropriate background color but somehow the image does not get displayed. here is my code. Character on canvas .canvas1 { background-color:grey; border:1px solid; }
</head>
<body>
<div id="imagediv">
<img id="spear1" src="E:\html-files\spear.png" style="height:150px; width:150px" draggable="true" ondrag="drag()" >
</div>
<div id="canvasdiv">
<canvas id="mainCanvas" class="canvas1" height="500px" width="600px"></canvas>
</div>
<script>
var canvas=document.getElementById("mainCanvas");
var ctx=canvas.getContext("2d");
var img=document.getElementById("spear1");
ctx.drawImage(img,0,0,160,160);
</script>
</body>