您的浏览器不支持 canvas遇新是直朋能到 标签
Demo
清除画布
clearIt();varimg= newImage();
img.οnlοad= function() {/** context.createPattern(image, repetitionStyle) - 指定贴图的平铺模式
* image - 图像对象。除了支持 HTMLImageElement 外,还支持 HTMLCanvasElement 和 HTMLVideoElement
* repetitionStyle - 平铺模式(无论任何平铺模式,首图均在画布的左上角)
* no-re中比需抖接朋功要朋插peat - 不平铺,只贴图一次,当然也是在画布的左上角
* repeat遇新是直朋能到分览-x - x 轴方向上平铺图片
* repeat遇新是直朋能到分览-y - y 轴方向上平铺图片
* repeat遇新是直朋能到 - x 轴和 y 轴方向均平铺图片*/varpattern=ctx.createPattern(img,"no-repeat");
ctx.fillStyle=pattern;
ctx.strokeStyle= "blue";
ctx.beginPath();
ctx.rect(0,0,300,300);
ctx.fill();
ctx.stroke();
pattern=ctx.createPattern(img,"repeat-x");
ctx.fillStyle=pattern;
ctx.strokeStyle= "blue";
ctx.beginPath();
ctx.rect(320,0,300,300);
ctx.fill();
ctx.stroke();
pattern=ctx.createPattern(img,"repeat-y");
ctx.fillStyle=pattern;
ctx.strokeStyle= "blue";
ctx.beginPath();
ctx.rect(0,320,300,300);
ctx.fill();
ctx.stroke();
pattern=ctx.createPattern(img,"repeat");
ctx.fillStyle=pattern;
ctx.strokeStyle= "blue";
ctx.beginPath();
ctx.rect(320,320,300,300);
ctx.fill();
ctx.stroke();
}
img.src= "http://res2.windows.microsoft.com/resbox/en/Windows%207/main/4300ae64-546c-4bbe-9026-6779b3684fb9_0.png";//img.src = "http://www.cnblogs.com/assets/windows_logo.png";}functionclearIt() {
ctx.clearRect(0,0,620,620);
}