anguage-dart"><code>var canvas = new CanvasElement(width: 600, height: 600);
var ctx = canvas.context2D;
var img = new ImageElement();
// Image src needs to be loaded before pattern is applied.
img.onLoad.listen((event) {
  // When the image is loaded, create a pattern
  // from the ImageElement.
  CanvasPattern pattern = ctx.createPattern(img, 'repeat');
  ctx.rect(0, 0, canvas.width, canvas.height);
  ctx.fillStyle = pattern;
  ctx.fill();
});
img.src = "images/foo.jpg";
document.body.children.add(canvas)