在数字成像中,当叠加两个视觉层时,您可以通过多种方式计算当来自较低层的光以某种方式穿过阻挡层时产生的图像。这可以提供自然现象不会出现的效果,例如多重颜色。
以下是 Photoshop 中提供的图层混合模式菜单的示例:
(来源:psdtop.com)
我建议访问文章了解混合模式 如果您不熟悉这个主题。它很好地展示了每个选项针对两层的结果。
据我所知,WPF 仅提供“正常”选项。也就是说,以下 UI 只是混合颜色,就好像它们是彩色凝胶一样:
<Grid>
<Ellipse Width="40" Height="40" Fill="#80FF0000" Margin="16,0,0,0" />
<Ellipse Width="40" Height="40" Fill="#8000FF00" Margin="32,32,0,0" />
<Ellipse Width="40" Height="40" Fill="#800000FF" Margin="0,32,0,0" />
</Grid>
看起来像这样:
我想知道是否有任何方法可以控制图层混合的方式。
In digital imaging, when overlaying two visual layers there are multiple ways you can calculate the image that results when light from a lower layer shines through an obstructing layer in some way. This can offer effects that do not occur as natural phenomenon, such as multiplying colours.
Here's an example of the layer blending mode menu provided in Photoshop:
(source: psdtop.com)
I recommend visiting the article Understanding Blending Modes if this topic isn't something you're familiar with. It provides a great showcase of the results of each option against two layers.
As far as I can tell, WPF only provides the 'Normal' option. That is, the following UI just blends colours as though they were coloured gels:
<Grid>
<Ellipse Width="40" Height="40" Fill="#80FF0000" Margin="16,0,0,0" />
<Ellipse Width="40" Height="40" Fill="#8000FF00" Margin="32,32,0,0" />
<Ellipse Width="40" Height="40" Fill="#800000FF" Margin="0,32,0,0" />
</Grid>
Which looks like this:
I'd like to know if there's any way to control the way in which layers blend.
发布评论
评论(3)
您正在寻找的称为混合模式。
这是一个简单的示例可以使用像素着色器来实现。您可以使用 多输入着色器效果 为此。
这是一个非常好的完整教程您可以使用多输入着色器效果创建可重复使用的混合模式库。
混合模式作为 WPF API 的固有部分经常出现自早期 CTP 以来就要求,但从未将其纳入产品中。
What you are looking for is called blend modes.
Here is a simple example of how it can be achieved using pixel shaders. You would use multi-input shader effect for this.
Here is a very good complete tutorial that walks you through creating a reusable library of blend modes using a multi-input shader effect.
Blend modes as an intrinsic part of the WPF APIs have been frequently requested since early CTPs but never made it into the product.
刚刚遇到这个问题...但您可以在某些情况下使用我的混合模式库来执行此操作(不幸的是存在一些限制...我们确实需要将此功能烧录到 WPF API 中)。
bitbonk 引用了我的博客系列中的第一篇文章……但每篇文章都附有混合模式库本身的源代码和二进制文件。
这是迄今为止的系列(按时间顺序排列)。我确实想再写一篇关于如何使用这些混合模式的文章......以及它们带来的价值。
modes-hue-saturation-color-and-luminosity-with-wpf-4-0/" rel="noreferrer">混合模式:WPF 4.0的 对于要使用的一组源代码/二进制文件,它将是 一个,我使混合模式库不透明度感知。这是适用于 WPF 和 Silverlight 的最新、最好的部分。最终的
祝你好运,如果你使用我的图书馆请告诉我!
Just ran into this question ... but you can use my blend mode library to do this in certain situations (unfortunately there are some limitations ... we really need this capability burned into the WPF API).
bitbonk references the beginning post in my blog series ... but every post has source code and binaries attached for the blend mode library itself.
Here is the series so-far (in chronological order). I do want to write one more post on how these blend modes can be used ... and what value they bring to the table.
If I could point you to one set of source code/binaries to use, it would be the one where I make the blend mode library opacity aware. This is the latest and greatest bits that work on both WPF and Silverlight. The final post which has the hue, saturation, color, and luminosity effects is a WPF only version of the library, as Pixel Shader 3.0 is required for these effects and currently only WPF 4.0 supports that.
Good luck and let me know if you use my library!
我相信您必须编写自定义着色器效果才能以不同的方式使 WPF 混合颜色。
http://msdn.microsoft.com/en-us /library/dd901594(VS.95).aspx
滚动到创建自定义像素着色器效果
据我所知,这不是一件小事。有时使用静态图形资源更容易妥协。我们的 UI 设计师无法忍受 WPF 颜色混合,因此我们界面的某些部分使用简单的 .png 文件,他绝对必须让它看起来像某种方式。
I believe you you'll have to write a custom shader effect to make WPF blend colors in a different way.
http://msdn.microsoft.com/en-us/library/dd901594(VS.95).aspx
Scroll to Creating a Custom Pixel Shader Effect
It's not a trivial thing, I understand. Sometimes it's easier to compromise by using static graphic resources. Our UI designer cannot live with WPF color blending, so some parts of our interface use simple .png files where he absolutely had to have it look a certain way.