2 背景图
ctx.createPattern(img,repeat)
第一个参数: 规定要使用的图片元素
第二个参数: 背景图平铺方式
- repeat : 默认。该模式在水平和垂直方向重复。
- repeat-x : 该模式只在水平方向重复。
- repeat-y : 该模式只在垂直方向重复。
- no-repeat: 该模式只显示一次(不重复)。
var ctx=c.getContext("2d");
var imgNode=document.getElementById("myImage");
var pat=ctx.createPattern(imgNode,"repeat");
ctx.rect(0,0,150,100);
ctx.fillStyle=pat; // 把背景图设置给填充的样式
ctx.fill();