Filling with an image file using repeat
<!DOCTYPE html> <html> <head> <style> #canvas { /*from w w w . ja va 2s.c o m*/ border:1px solid #03F; background:#CFC; } </style> </head> <body> <canvas id="canvas" width="640" height="480"></canvas> <script> let context = document.getElementById('canvas').getContext('2d'); let fillImg = new Image(); fillImg.src = 'http://java2s.com/style/download.png'; fillImg.onload = function(){ let fillPattern = context.createPattern(fillImg,'repeat'); context.fillStyle = fillPattern; context.fillRect(0,0,200,200); } </script> </body> </html>