admin管理员组文章数量:1431400
I'm new to HTML5 canvas and I want to reproduce the result of BlendMode.ADD
in ActionScript 3.
According to the documentation, here's what BlendMode.ADD
does:
Adds the values of the constituent colors of the display object to the colors of its background, applying a ceiling of 0xFF. This setting is monly used for animating a lightening dissolve between two objects.
For example, if the display object has a pixel with an RGB value of 0xAAA633, and the background pixel has an RGB value of 0xDD2200, the resulting RGB value for the displayed pixel is 0xFFC833 (because 0xAA + 0xDD > 0xFF, 0xA6 + 0x22 = 0xC8, and 0x33 + 0x00 = 0x33).
Source: .html#ADD
How can I do the same thing to an image in HTML5 Canvas?
I'm new to HTML5 canvas and I want to reproduce the result of BlendMode.ADD
in ActionScript 3.
According to the documentation, here's what BlendMode.ADD
does:
Adds the values of the constituent colors of the display object to the colors of its background, applying a ceiling of 0xFF. This setting is monly used for animating a lightening dissolve between two objects.
For example, if the display object has a pixel with an RGB value of 0xAAA633, and the background pixel has an RGB value of 0xDD2200, the resulting RGB value for the displayed pixel is 0xFFC833 (because 0xAA + 0xDD > 0xFF, 0xA6 + 0x22 = 0xC8, and 0x33 + 0x00 = 0x33).
Source: http://help.adobe./en_US/FlashPlatform/reference/actionscript/3/flash/display/BlendMode.html#ADD
How can I do the same thing to an image in HTML5 Canvas?
Share Improve this question edited Mar 11, 2017 at 22:20 JeePing asked Mar 11, 2017 at 21:26 JeePingJeePing 4891 gold badge7 silver badges16 bronze badges1 Answer
Reset to default 4The specification of the 2D canvas has implemented the blending mode with the name "lighter" (not to be confused with "lighten" which is a different mode) that will do "add".
var ctx = c.getContext("2d");
ctx.fillStyle = "#037";
ctx.fillRect(0, 0, 130, 130);
ctx.globalCompositeOperation = "lighter"; // AKA add / linear-dodge
ctx.fillStyle = "#777";
ctx.fillRect(90, 20, 130, 130);
<canvas id=c></canvas>
(update: I was remembering (incorrectly) lighten as the name for it, so sorry for the extra manual step in the original version of the answer).
本文标签: javascriptHTML5 Canvas blendmodeStack Overflow
版权声明:本文标题:javascript - HTML5 Canvas blendmode - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745559910a2663411.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论