是否可以将绘制的图形存储到临时位图中,以便以后在 HTML5 画布上进行 alpha 合成?
我正在使用 HTML5 画布制作某种 UI 层。所有图层都可以嵌套并且可以有 Alpha。嵌套图层应使用正确的 alpha 成分绘制。为此,需要某种临时位图存储。如何将图形存储到临时位图中?
I'm making some kind of UI layers with HTML5 canvas. All layers can be nested and can have alpha. Nested layers should be drawn with correct alpha composition. To do this, some kind of temporary bitmap storage is required. How can I store graphics drawing into temp bitmap?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您始终可以在内存中创建画布(就像不将其添加到 DOM 中一样)
storedCanvas = document.createElement('canvas');
然后您可以将整个画布绘制到该画布上:
storedCtx.drawImage(firstCanvas, 0, 0);
然后你可以对第一个画布做任何你想做的事情,存储的画布不会改变。然后,当您想回忆起这一点时,只需执行
firstCanvasCtx.drawImage(storedCanvas, 0, 0);
You can always make a canvas in memory (as in not add it to the DOM)
storedCanvas = document.createElement('canvas');
Then you can paint an entire canvas to that canvas:
storedCtx.drawImage(firstCanvas, 0, 0);
Then you can do whatever you want to the first canvas, the stored one won't change. Then, when you want to recall that, you just do
firstCanvasCtx.drawImage(storedCanvas, 0, 0);