WPF - 控制半透明层之间的混合 [英] WPF - Control over blending between semi-transparent layers

查看:18
本文介绍了WPF - 控制半透明层之间的混合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在数字成像中,当叠加两个视觉层时,您可以通过多种方式计算当来自较低层的光以某种方式穿过阻挡层时产生的图像.这可以提供不会作为自然现象发生的效果,例如颜色相乘.

以下是 Photoshop 中提供的图层混合模式菜单的示例:


(来源:

我想知道是否有任何方法可以控制图层混合的方式.

解决方案

您正在寻找的称为混合模式.

这是一个简单的示例如何使用像素着色器实现它.您将使用 多输入着色器效果为此.

这是一个非常好的完整教程 指导您使用多输入着色器效果创建可重复使用的混合模式库.

混合模式作为 WPF API 的内在部分经常从早期的 CTP 开始请求,但从未将其纳入产品.

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.

解决方案

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 - 控制半透明层之间的混合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆