2

I want to combine blur, Saturation and tint color.

I have a Blend effect, that consist of GaussianBlur and Tint color.

_compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
var graphicsEffect = new BlendEffect
{
 Mode = BlendEffectMode.Overlay,
 Background = new GaussianBlurEffect()
 {
 Name = "Blur",
 Source = new CompositionEffectSourceParameter("Backdrop"),
 BlurAmount = 10f
 BorderMode = EffectBorderMode.Hard,
 },
 Foreground = new ColorSourceEffect()
 {
 Name = "Tint",
 Color = Color.FromArgb(120, 255, 255, 255),
 }
};
var effectFactory = _compositor.CreateEffectFactory(graphicsEffect)
_brush = effectFactory.CreateBrush();
_brush.SetSourceParameter("Backdrop", _compositor.CreateBackdropBrush());
_effectSprite = _compositor.CreateSpriteVisual();
_effectSprite.Size = new Vector2((float)this.ActualWidth, (float)this.ActualHeight)
_effectSprite.Brush = _brush;
ElementCompositionPreview.SetElementChildVisual(this, _effectSprite)

How do I add SaturationEffect before or after this effect?

I've tried to wrap it into another BlendEffect and set another BackdropBrush as a source of the SaturationEffect, but I got white background only.

I've also tried to create brush from SaturationEffect and set it a a source of GaussianBlur, but I got exception "Invalid Source Brush"

Jay Zuo
15.8k2 gold badges30 silver badges51 bronze badges
asked Dec 12, 2016 at 12:41

1 Answer 1

6

Here's an example:

(input) Backdrop -> GaussianBlur ->|
 ColorSource ->| Blend -> Saturation (output)
var compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
var blurEffect = new GaussianBlurEffect()
{
 Name = "Blur",
 BlurAmount = 0.0f,
 BorderMode = EffectBorderMode.Hard,
 Optimization = EffectOptimization.Balanced,
 Source = new CompositionEffectSourceParameter("source"),
};
var colorEffect = new ColorSourceEffect
{
 Name = "Tint",
};
var blendEffect = new BlendEffect
{
 Background = blurEffect,
 Foreground = colorEffect,
 Mode = BlendEffectMode.Overlay,
};
var saturationEffect = new SaturationEffect
{
 Name = "Saturation",
 Source = blendEffect,
 Saturation = 1.5f,
};
var factory = compositor.CreateEffectFactory(saturationEffect, new[]
{
 "Blur.BlurAmount",
 "Tint.Color",
 "Saturation.Saturation",
});
var brush = factory.CreateBrush();
brush.SetSourceParameter("source", compositor.CreateBackdropBrush());
// Animatable properties
brush.Properties.InsertScalar("Blur.BlurAmount", 10);
brush.Properties.InsertColor("Tint.Color", Color.FromArgb(20, 255, 0, 0));
brush.Properties.InsertScalar("Saturation.Saturation", 1.5f);
var sprite = compositor.CreateSpriteVisual();
sprite.Brush = brush;
sprite.Offset = new Vector3(50, 250, 0);
sprite.Size = new Vector2(200, 200);
ElementCompositionPreview.SetElementChildVisual(this, sprite);

Screenshot

answered Dec 12, 2016 at 22:05
Sign up to request clarification or add additional context in comments.

1 Comment

This works perfectly, why hasn't it been marked as an answer already?

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.