CanvasRenderingContext2D.fill()
CanvasRenderingContext2D.fill()
是 Canvas 2D API 根据当前的填充样式,填充当前或已存在的路径的方法。采取非零环绕或者奇偶环绕规则。
语法
void ctx.fill(); void ctx.fill(fillRule); void ctx.fill(path, fillRule);
参数
示例
填充矩形
这是一段简单的代码片段,使用 fill
方法填充路径。
HTML
<canvas id="canvas"></canvas>
JavaScript
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
ctx.rect(10, 10, 150, 100);
ctx.fill();
结果
规范
Specification |
---|
HTML Standard # dom-context-2d-fill-dev |
浏览器兼容性
BCD tables only load in the browser
参见
- 接口定义,
CanvasRenderingContext2D
.