HTML canvas fill () method
Examples
Draw a rectangle 150 * 100 pixels, then fill it with red to give:
JavaScript:
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.rect(20,20,150,100);
ctx.fillStyle="red";
ctx.fill();
var ctx=c.getContext("2d");
ctx.rect(20,20,150,100);
ctx.fillStyle="red";
ctx.fill();
try it"
Browser Support
Internet Explorer 9, Firefox, Opera, Chrome and Safari support fill () method.
Note: 8 and earlier versions of Internet Explorer do not support the <canvas> element.
Definition and Usage
fill () method fills the current image (path). The default color is black.
Tip: Use fillStyle property to populate another color / gradient.
Note: If thepath is not closed, the fill () method to add the path to the end point of a line between the start point to close the path (as closePath () the same), then fill the path.
JavaScript syntax: | context .fill ( ); |
---|
HTML canvas Reference Manual