OffscreenCanvasRenderingContext2D: commit() 方法
注意:此功能在 Web Workers 中可用。
已弃用:此特性不再推荐。虽然某些浏览器可能仍然支持它,但它可能已经从相关的网络标准中删除,可能正在删除过程中,或者可能仅为兼容性目的而保留。请避免使用它,如果可能,请更新现有代码;请参阅本页底部的兼容性表格以指导您的决策。请注意,此特性可能随时停止工作。
非标准:此特性未标准化。我们不建议在生产环境中使用非标准特性,因为它们浏览器支持有限,并且可能会更改或被移除。但是,在没有标准选项的特定情况下,它们可以是合适的替代方案。
OffscreenCanvasRenderingContext2D.commit() 方法是 Canvas 2D API 的一部分,它旨在将渲染上下文的位图复制到关联的 OffscreenCanvas 对象的占位符 <canvas> 元素的位图中。复制操作是同步的。对于传输而言,调用此方法并非必需,因为它会在事件循环执行期间自动发生。
语法
js
commit()
参数
无。
返回值
无(undefined)。
示例
js
const placeholder = document.createElement("canvas");
const offscreen = placeholder.transferControlToOffscreen();
const ctx = offscreenCanvas.getContext("2d");
// Perform some drawing using the 2d context
ctx.fillStyle = "blue";
ctx.fillRect(0, 0, 10, 10);
// Push placeholder to the canvas element
ctx.commit();
规范
不属于任何规范。
浏览器兼容性
加载中…
另见
- 定义此方法的接口:
OffscreenCanvasRenderingContext2D