javascript 模糊 HTML5 画布

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14751032/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 22:29:31  来源:igfitidea点击:

Blur HTML5 Canvas

javascripthtml5-canvas

提问by starbeamrainbowlabs

How can I blur the contents of an HTML5 canvas?

如何模糊 HTML5 画布的内容?

I know that I can use CSS, but I need to blur the contents of the canvas so that I can manipulate it later.

我知道我可以使用 CSS,但我需要模糊画布的内容,以便我以后可以对其进行操作。

采纳答案by Philipp

There is no native function to do that. But you can implement your own image filter operations by using context.getImageDatato get an array of raw RGBA values of the canvas data, do your filter operation on that data, and then write it back with context.putImageData.

没有本机功能可以做到这一点。但是您可以通过使用context.getImageData获取画布数据的原始 RGBA 值数组来实现自己的图像过滤操作,对该数据执行过滤操作,然后使用context.putImageData.

http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#pixel-manipulation

http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#pixel-manipulation