Win2D 效果仅在内容尚未变暗时才使内容变暗?

Win2D effect to make content darker only if it isn't already?

我正在处理一些 Win2D 效果,但我很难找到合适的方法来使我的 UI 内容足够暗,以便上面的文字足够容易阅读。

现在这是我的代码的一部分:

ArithmeticCompositeEffect composite = new ArithmeticCompositeEffect
{
    MultiplyAmount = 0,
    Source1Amount = 0.2f,
    Source2Amount = 0.8f,
    // The Source1 parameter will be assigned later on with the EffectFactory
    Source1 = new CompositionEffectSourceParameter(nameof(myBackground)),
    Source2 = new ColorSourceEffect { Color = Colors.Black }
};

所以我将我的内容 (Source1) 与统一的黑色混合,这有效地使整个内容变暗了。不过我有一个问题:

我听说可以使用模式设置为 BlendEffectMode.ExclusionBlendEffect 来解决这个问题,但我不知道如何正确设置它。我尝试使用此效果将我的第一个效果与统一的黑色结合起来,但结果没有任何变化。

所以我的问题是:

Which Win2D effect (not necessarily an exclusion blend if that's not the right choice here) can I apply to make sure that my content is always darker than a given threshold (so dark enough), without making content that's already dark practically black?

感谢您的帮助!

我发现可以使用 LuminanceToAlphaEffect Win2D 效果并将生成的贴图覆盖在原始效果上(可能具有一定的强度以使原始图像或多或少变暗,具体取决于关于情况)。

例如:

LuminanceToAlphaEffect alphaEffect = new LuminanceToAlphaEffect 
{ 
    Source = new CompositionEffectSourceParameter(nameof(myBackground))
};
ArithmeticCompositeEffect composite = new ArithmeticCompositeEffect
{
    MultiplyAmount = 0,
    Source1Amount = 1 - intensity, // Intensity is in the [0..1] range
    Source2Amount = intensity,
    // The Source1 parameter will be assigned later on with the EffectFactory
    Source1 = new CompositionEffectSourceParameter(nameof(myBackground)),
    Source2 = alphaEffect    
};