CanvasContext.fill
更新时间:2022-07-13 12:44:45

注意:该接口已停止维护,建议使用 Canvas 组件 V2

基础库 1.0.0 开始支持本方法,这是一个同步方法。

对当前路径中的内容进行填充。默认的填充色为黑色。

语法

CanvasContext.fill();
复制代码

参数说明

返回值

扫码体验

请使用字节宿主APP扫码

代码示例

开发者工具中预览

【示例 1】路径没有闭合时填充:

<!-- index.ttml --> <canvas canvas-id="myCanvas"></canvas>
复制代码
// index.js Page({ onLoad: function (options) { const ctx = tt.createCanvasContext("myCanvas"); ctx.moveTo(10, 10); ctx.lineTo(100, 10); ctx.lineTo(100, 100); ctx.fill(); ctx.draw(); }, });
复制代码

【示例 2】不包含 fillRect:

<!-- index.ttml --> <canvas canvas-id="myCanvas"></canvas>
复制代码
// index.js Page({ onLoad: function (options) { const canvasCtx = tt.createCanvasContext("myCanvas"); canvasCtx.rect(10, 10, 100, 30); canvasCtx.setFillStyle("yellow"); canvasCtx.fill(); // 路径开始 canvasCtx.beginPath(); canvasCtx.rect(30, 40, 100, 30); // 该样式仅适用于fillRect canvasCtx.setFillStyle("blue"); canvasCtx.fillRect(50, 70, 100, 30); canvasCtx.rect(70, 100, 100, 30); // 该样式适用从 beginPath 起始到 fill canvasCtx.setFillStyle("red"); canvasCtx.fill(); canvasCtx.draw(); }, });
复制代码

Bug & Tip

点击纠错
该文档是否对你的开发有所帮助?
有帮助
没帮助
该文档是否对你的开发有所帮助?
有帮助
没帮助
https://developer.open-douyin.com/forum/activity/post/64586644efa15e3e15723269