日期:2014-05-17  浏览次数:20620 次

html5 canvas导入本地存储的一幅图失败,急求指导,实在不知道哪里错了
我用html5 canvas导入我的一副image图片,这是我的代码。。我查过网上好多关于这方面的,已经觉得没有错了,可是一按F12,进入网页显示之后显示的是一片空白,什么图片都没有!!!!急求高手指导啊啊啊啊!
<!DOCTYPE HTML>
<html>
<head>
<title>PS images showing</title>
<script type="application/x-javascript">

function loadimage(){
var canvas = document.getElementById("canvas");  
  var context = canvas.getContext("2d");  
  var image = new Image();
  image.src = "images0.JPG";
context.drawImage(image,0,0);

}
</script>
</head>

<body onload = "loadimage()">
 <canvas id="canvas" width="2000" height="3000"></canvas>  
</body>
</html>

------解决方案--------------------
你分别试验以下三种情况:
1、显示空白后F5再刷新一次
2、把width="2000" height="3000"去掉,或设成与图像同样大小
3、不在onload中调用,弄个按钮,点击时loadimage
------解决方案--------------------
HTML code

<!DOCTYPE HTML>
<html>
<head>
<title>PS images showing</title>

</head>

<body onload = "loadimage()">
 <canvas id="canvas" width="2000" height="3000"></canvas>  
 <script>
var canvas = document.getElementById("canvas");  
  var context = canvas.getContext("2d");  
  var image = new Image();
  image.src = "images0.JPG";
function loadimage(){

context.drawImage(image,0,0);
}
</script>
</body>
</html>