下面代码哪里错了,为什么画布中就是不显示图片

来源:3-2 绘制图像及使用剪辑区域

momoyy123

2016-07-05 16:10

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Document</title>

<style>

*{margin: 0; padding: 0;}

a{text-decoration: none; font-family: "microsoft yahei"}

.blur-img{position: relative; width: 1440px; height: 900px; margin: 0 auto;}

.blur-img img{width: 1440px; height: 900px; filter: blur(20px);-webkit-filter: blur(20px); -moz-filter:blur(20px); -o-filter:blur(20px); -ms-filter:blur(20px); z-index: 1;}

#canvas{position: absolute; left: 0; top: 0; z-index: 100; display: block;}

.blur-btn{position: absolute; bottom: 0; width: 80px; height: 30px; text-align: center; line-height: 30px; font-size: 16px; color: #fff; background: #218868; display: block; z-index: 102;}

.blur-btn.reset{left: 200px;}

.blur-btn.show{right: 200px; background: #CD69C9;}

</style>

</head>

<body>

<div>

<img src="images/1.jpg" alt="">

<canvas id="canvas">

该浏览器不支持canvas,请更换

</canvas>

<a href="##" class="blur-btn reset">RESET</a>

<a href="##" class="blur-btn show" >SHOW</a>

</div>

<script>

var canvasWidth = 1440;

var canvasHeight = 900;

var canvas = document.getElementById("canvas");

var context = canvas.getContext("2d");


canvas.width = canvasWidth;

canvas.height = canvasHeight;


var image = new Image();

image.src = "1.jpg";

image.onload = function(e){

context.drawImage(image,0,0);

}

</script>

</body>

</html>


写回答 关注

1回答

  • 守得云开见月
    2016-07-07 13:28:33

    image.src = "1.jpg";

    上面这段代码少了文件夹名称。

    image.src = "images/1.jpg";

Canvas玩儿转红包照片

教你玩儿转微信红包照片模糊效果,图像展示效果,深入了解canvas

55911 学习 · 67 问题

查看课程

相似问题