Returns a CanvasPattern object that uses the given image and repeats in the direction(s) given by the repetition argument.
Method of apis/canvas/CanvasRenderingContext2Dapis/canvas/CanvasRenderingContext2D
Syntaxvar object = object.createPattern(image, repetition);
Parameters image
An image, canvas, or video element of the pattern to use. If the image has no image data, throws an InvalidStateError exception. If the image is not yet fully decoded, the method returns null.
repetitionThe direction of repetition. The allowed values for repetition are:
If the parameter does not match one of the allowed values, the method throws a SyntaxError exception.
Return ValueReturns an object of type DOM NodeDOM Node
CanvasPattern
The pattern object to use as a fill style together with a CanvasRenderingContext2D object.
ExamplesThis example uses an image in the page (repeated in both directions) as a pattern, then places a rectangle filled with that pattern onto the canvas.
<img id="qmark" src="qmark.png" width="16px" height="16px" style="visibility:hidden"/>
<canvas id="myCanvas" width="300" height="150" style="border:1px solid blue;"></canvas>
<p>. . .</p>
<script>
var can = document.getElementById("myCanvas");
var ctxt = can.getContext("2d");
var image=document.getElementById("qmark");
var patn=ctxt.createPattern(image,"repeat");
ctxt.rect(0,0,150,100);
ctxt.fillStyle=patn;
ctxt.fill();
</script>
Notes
If the repetition parameter equals null or an empty string, the method defaults to "repeat".
Related specificationsMicrosoft Developer Network: Windows Internet Explorer API reference Article
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4