<!DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"> <title>Document</title></Head><Body> <CanvasID= "Canvas"style= "margin:0 auto;border:1px #ddd solid;">the current browser does don't support Canvas, can replace the browser a try! </Canvas> <Script>window.onload= function(){ varCanvas=document.getElementById ('Canvas'); Canvas.width= -; Canvas.height= -; if(Canvas.getcontext ('2d')){ varContext=Canvas.getcontext ('2d'); //begin varbackgroundimage= NewImage (); BACKGROUNDIMAGE.SRC= "Img/1.png"; Backgroundimage.onload= function(){ varpattern=Context.createpattern (backgroundimage,'Repeat'); Context.fillstyle=pattern; Context.fillrect (0,0, Canvas.width,canvas.height)} }Else{alert ('the current browser does not support canvas, please change the viewer and try again! '); } } </Script></Body><Script> /*Summary//Fill picture Createpattern (img,repeat-style) repeat-style:repeat-x repeat-y Repeat no-repeat//fill canvas Createpattern (canvas,repeat-style)//Fill Video Createpattern (Video,repeat-style)*/</Script></HTML>
Canvas-4createpattern.html