码迷,mamicode.com
首页 > 其他好文 > 详细

fillStyle图片填充

时间:2016-05-11 10:54:41      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:

图片自找

<!DOCTYPE HTML> <head> <meta charset = "utf-8"> <title>canvas</title> <style type="text/css"> #canvas{border:1px solid #eee ; display:block; background-color: #B36666; margin: 20px auto; } </style></head><body><div><canvas id = "canvas" width = "800px" height = "800px"></canvas></div> <script type = "text/javascript" >
window.onload=function(){
var context = document.getElementById(‘canvas‘).getContext(‘2d‘)

/*
context.createPattern(img‘repeat-style‘);
repeat-style参数可以是:
‘no-repeat‘ 不重复
‘repeat‘ x,y轴重复
‘repeat-x‘ x轴重复
‘repeat-y‘ y轴重复

扩展:context.createPattern(img‘repeat-style‘)方法参数:
可以是image图片作为参数,
可以是canvas对象作为参数
可以是video视频对象作为参数

总结:context.fillStyle 可以等于以下参数
color 
gradient
image
canvas
video;

*/
var image1 = new Image();
image1.src = ‘1.png‘;
image1.onload = function(){
var pattern = context.createPattern(image1,‘repeat‘);
context.fillStyle=pattern;
context.fillRect(0,0,800,800);
}
}
</script> </body> </html>

fillStyle图片填充

标签:

原文地址:http://www.cnblogs.com/vs1435/p/5480887.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!