javascript canvas里面不出图片为什么
<!DOCTYPEhtml><html><body><p>Imagetouse:</p><imgid="scream"src="d:\lm.jpg"width="200"...
<!DOCTYPE html>
<html>
<body>
<p>Image to use:</p>
<img id="scream" src="d:\lm.jpg" width="200" height="200">
<p>Canvas:</p>
<canvas id="myCanvas" width="500" height="500" style="border:1px solid #d3d3d3">
Your browser does not support the HTML5 canvas tag.</canvas>
<script type = "text/javascript">
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
var img=document.getElementById("scream");
ctx.drawImage(img,10,10);
/* ctx.moveTo(0, 0);
ctx.lineTo(200, 200);
ctx.stroke(); */
</script>
</body>
</html> 展开
<html>
<body>
<p>Image to use:</p>
<img id="scream" src="d:\lm.jpg" width="200" height="200">
<p>Canvas:</p>
<canvas id="myCanvas" width="500" height="500" style="border:1px solid #d3d3d3">
Your browser does not support the HTML5 canvas tag.</canvas>
<script type = "text/javascript">
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
var img=document.getElementById("scream");
ctx.drawImage(img,10,10);
/* ctx.moveTo(0, 0);
ctx.lineTo(200, 200);
ctx.stroke(); */
</script>
</body>
</html> 展开
4个回答
展开全部
路径对?对的话试试这个,你的貌似少了@
<img id="scream" src=@"d:\lm.jpg" width="200" height="200">
<img id="scream" src=@"d:\lm.jpg" width="200" height="200">
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
图片加载完后才能呈现到canvas
img.onload = function () {
cxt.drawImage(img, 0, 0);
}
img.onload = function () {
cxt.drawImage(img, 0, 0);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
不用说了,图片路径不对!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询