我有一个覆盖纯色背景的非常大的 html Canvas 元素。我假设如果浏览器没有将 Canvas 与其背后的元素混合(在本例中为纯色),则在滚动/平移时可以节省大量 CPU。
是否可以删除 Canvas alpha channel ?这应该留给浏览器来检测和优化吗?还是速度提升微不足道?
最佳答案
MDN suggests在 Canvas 上下文中设置 alpha 选项:
If your application uses canvas and doesn’t need a transparent backdrop, set the
alpha
option tofalse
when creating a drawing context withHTMLCanvasElement.getContext()
. This information can be used internally by the browser to optimize rendering.
var ctx = canvas.getContext('2d', { alpha: false });
关于optimization - 删除 HTML Canvas alpha channel ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3008538/