HTML5 中是否可以实现类似 Photoshop 的混合模式?

发布于 2024-10-04 13:16:12 字数 249 浏览 9 评论 0原文

我想在我的网页上放置一个红色矩形

元素,这样它不仅看起来是透明的,而且就像在 Photoshop 的乘法模式中混合的一样。

将具有 position:fixed,因此其下方的内容会快速更改。

任何 HTML5 / CSS3 / canvas / SVG 技巧都可以实现吗?

I want to put a red rectangular <div> element over my webpage so that it would look not only transparent, but also like blended in Photoshop’s Multiply mode.

The <div> would have position: fixed, so the content below it would change quickly.

Is that possible with any HTML5 / CSS3 / canvas / SVG trick?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

洛阳烟雨空心柳 2024-10-11 13:16:12

我创建了一个单独的、轻量级的开源库,用于从一个 HTML Canvas 上下文到另一个上下文执行 Photoshop 风格的混合模式:

// Might be an 'offscreen' canvas
var over  = someCanvas.getContext('2d');
var under = anotherCanvas.getContext('2d');

over.blendOnto( under, 'screen', {destX:30,destY:15} );

请参阅 README 了解更多信息,包括当前支持的混合模式。

您可以使用它来执行从一个画布到另一个画布的乘法,但不能在标准 HTML 元素上执行。

I have created a separate, lightweight, open-source library for perform Photoshop-style blend modes from one HTML Canvas context to another: context-blender. Here's the sample usage:

// Might be an 'offscreen' canvas
var over  = someCanvas.getContext('2d');
var under = anotherCanvas.getContext('2d');

over.blendOnto( under, 'screen', {destX:30,destY:15} );

See the README for more information, including the currently-supported blend modes.

You could use this to perform multiply from one canvas to another, but not over standard HTML elements.

╰ゝ天使的微笑 2024-10-11 13:16:12

您还可以查看此演示:http://media.chikuyonok.ru/canvas-blending/ 了解如何用画布来做到这一点。

检查混合模式公式的来源以及如何应用它们(公式比 pixastic 或 context-blender 中的公式更具可读性)。

You can also look at this demo: http://media.chikuyonok.ru/canvas-blending/ to see how to do this with canvas.

Check the source for blending modes' formulae and how to apply them (formulae are much more readable than in pixastic or context-blender).

2024-10-11 13:16:12

这不是 HTML5,但它是我能找到的最接近您所要求的内容的。

Javascript 混合模式 (OpenGL)。

我不认为像 Photoshop 这样的“混合模式”可以仅用纯 HTML 来模拟,除非该语言朝另一个方向急剧转变。但很高兴看到一些更简单的方法来做到这一点。

This isn't HTML5, but it's as close as I can find for what you're asking.

Javascript blending modes (OpenGL).

I don't think "blend modes" like Photoshop could be emulated with just pure HTML, unless the language took a sharp turn in another direction. But it would be great to see some easier way of doing this.

几度春秋 2024-10-11 13:16:12

我也对此非常感兴趣。我为视觉设计师编写的许多布局都可以使用它。除了本线程中的其他帖子之外,还有一种方法可以做到这一点,目前仅在 Firefox 4 中,无需使用 OpenGL 或 Canvas。这是通过使用 SVG 过滤器实现的。显然,Webkit 和 Chrome 的睡衣上也有这个功能,但我还没有看到任何功能。

以下是一些演示和说明:(

恕我直言,任何接近混合模式的东西现在都很难实现。很难找到有关 feConvolveMatrix、feSpecularLighting 或 feColorMatrix 的任何参考资料,而且这些示例对我来说根本无法理解。他们可以工作,但我不知道如何。

我希望像 EffectGames 建议这样的东西:

div.sprite {
   position: absolute;
   z-index: 2;
   composite: add;
}

这会更好方法。也许那里的一些精通数学的忍者可以让我们有能力做到这一点。

编辑:有一个更简单的 SVG 规范可以精确地执行混合模式。但我测试的浏览器都没有这个功能(FF4、IE9、Opera11、Webkit Nightly): http://dev.w3.org/SVG/modules/compositing/master/SVGCompositingPrimer.html - 但我也不知道这是否可以在 HTML-DOM 元素中使用。

I am also very interested in doing that. Many layouts that I coded for visual designers could have used that. Aside from the other posts in this thread, there is a way to do this, currently only in Firefox 4, without using OpenGl or Canvas. It's trough the use of SVG filters. Aparrently it's on nighties from Webkit and Chrome also, but I couldn't see anything working yet.

Here are some demos and explanations:

IMHO something anyware close to blend modes are too much hard to achieve right now. It's very hard to find any references on feConvolveMatrix, feSpecularLighting, or feColorMatrix, and the examples are just impossible to figure out for me. They could work but I don't know how.

I wish something like EffectGames suggested:

div.sprite {
   position: absolute;
   z-index: 2;
   composite: add;
}

This would be a way better approach. Maybe some ninja there skiled in mathematics could make us a lib to do that.

EDIT: There is an easier SVG spec to do exactly blend modes. But no browser that I tested have this working (FF4, IE9, Opera11, Webkit Nightly): http://dev.w3.org/SVG/modules/compositing/master/SVGCompositingPrimer.html - But I also don't know if this will be possible to use in HTML-DOM elements.

琴流音 2024-10-11 13:16:12

这是我见过的最接近的,并且是的,所有资源都必须在画布中。请注意,Internet Explorer 在版本 9 中开始支持画布,该版本尚未发布,因此如果您必须支持 IE<9,则必须使用解决方法。

This is the closest I have seen, and yes, all assets have to be in the canvas. Note that Internet Explorer starts supporting canvas in version 9 which is not out yet, so if you have to support IE<9 you'll have to use a workaround.

執念 2024-10-11 13:16:12

您已经可以通过简单的 CSS(无 Canvas)来使用它。示例:

mix-blend-mode: 'multiply'

Internet Explorer 可能不支持它,但其他浏览器支持。

https://developer.mozilla.org/en-US /docs/Web/CSS/mix-blend-mode

You can already use it with just simple CSS (no Canvas). Example:

mix-blend-mode: 'multiply'

Internet Explorer may not support it, but the other browsers do.

https://developer.mozilla.org/en-US/docs/Web/CSS/mix-blend-mode

远山浅 2024-10-11 13:16:12

根据所涉及的图像和您想要的确切效果,您也许可以对图像和 CSS 渐变进行一些创造性的分层,以达到所需的效果:

http://jonathonhill.net/2012-04-23/blending-css-gradients-like-photoshop/

Depending on the images involved and the exact effect you are after, you might be able to do some creative layering of images and CSS gradients to achieve the desired affect:

http://jonathonhill.net/2012-04-23/blending-css-gradients-like-photoshop/

暖伴 2024-10-11 13:16:12

我已经使用 http://canvasquery.com/ 中的画布实现了 gimp/photoshop 中已知的最流行的混合模式,但是它是不适合关系。

随着画布中引入本机混合模式

https: //dvcs.w3.org/hg/FXTF/rawfile/tip/compositing/index.html#blendingseparable

I have implemented most popular blend modes known from gimp/photoshop using canvas in http://canvasquery.com/ however it is not suitable for relatime.

This will change with introduction of native blend modes in canvas

https://dvcs.w3.org/hg/FXTF/rawfile/tip/compositing/index.html#blendingseparable

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文