CompositionEffectBrush CompositionEffectBrush CompositionEffectBrush CompositionEffectBrush Class

Definition

Paints a SpriteVisual with the output of a filter effect. The filter effect description is defined using the CompositionEffectFactory class.

public : sealed class CompositionEffectBrush : CompositionBrush, ICompositionEffectBrush
struct winrt::Windows::UI::Composition::CompositionEffectBrush : CompositionBrush, ICompositionEffectBrush
public sealed class CompositionEffectBrush : CompositionBrush, ICompositionEffectBrush
Public NotInheritable Class CompositionEffectBrush Inherits CompositionBrush Implements ICompositionEffectBrush
Inheritance
CompositionEffectBrushCompositionEffectBrushCompositionEffectBrushCompositionEffectBrush
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10586.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v2)

Examples


// Create an effect description 
GaussianBlurEffect blurEffect = new GaussianBlurEffect() 
{ 
    Name = "Blur", 
    BlurAmount = 1.0f, 
    BorderMode = EffectBorderMode.Hard, 
    Optimization = EffectOptimization.Balanced 
}; 

blurEffect.Source = new CompositionEffectSourceParameter("source"); 

CompositionEffectFactory blurEffectFactory = _compositor.CreateEffectFactory(blurEffect); 
CompositionEffectBrush blurBrush = blurEffectFactory.CreateBrush(); 
// Create a BackdropBrush and bind it to the EffectSourceParameter “source” 
CompositionBackdropBrush backdropBrush = _compositor.CreateBackdropBrush(); 
blurBrush.SetSourceParameter("source", backdropBrush); 

// The SpriteVisual to apply the blur BackdropBrush to 
// This will cause everything behind this SpriteVisual to be blurred 
SpriteVisual blurSprite = _compositor.CreateSpriteVisual(); 
blurSprite.Brush = blurBrush; 

// Set blurSprite as a child visual of a XAML element 
ElementCompositionPreview.SetElementChildVisual(blurArea, blurSprite); 

Remarks

The effect APIs enable developers to customize how their UI is rendered. This can be something as simple as adjusting saturation levels on an image or something more complex like chaining numerous effects together and animating the effect properties to create interesting application transitions and user experiences. A composition effect is a graph of operations that define how to produce graphical content based on composition surfaces. For example, the pixel content of images. Effects are applied to visuals in the tree and can reference existing surfaces.

An instance of CompositionEffectBrush is created using a CompositionEffectFactory based on a specified effect description. CompositionEffectFactory uses the Win2D effect description format in the Microsoft.Graphics.Canvas.Effects namespace.

Note

Effects that are not supported are marked as [NoComposition] in the Win2D API Reference for effects namespace.

A CompositionEffectBrush is applied to a SpriteVisual in the composition tree.

Sources to CompositionEffectBrush can be an existing surface or texture, or another effect enabling effect chaining.

CompositionEffectBrush.Properties (inherited from CompositionObject.Properties) allows setting or animating the animatable properties that were specified in the call to Compositor.CreateEffectFactory using their full 'EffectName.PropertyName' name.

Effect sources can be set independently from other CompositionEffectBrush instances, and properties can be animated independently from other CompositionEffectBrush instances.

Once an effect graph is declared, the system compiles the effect using built-in shaders. Custom shaders cannot be specified.

Creating a CompositionEffect

To create and apply an effect you need to perform the following steps:

  1. Create an effect description. See the Win2D namespace, Microsoft.Graphics.Canvas.Effects, for valid effect types.
  2. Set any effect sources with either an instance of CompositionEffectSourceParameter or another effect. Specifying another effect creates an effect chain.
  3. Create a CompositionEffectFactory with Compositor.CreateEffectFactory using the effect description as input.
  4. Create an instance of the effect using CompositorEffectFactory.CreateBrush.
  5. Set any CompositionEffectSourceParameter using CompositionEffectBrush.SetSourceParameter and the name of the source parameter as previously specified using a CompositionEffectSourceParameter.
  6. Create an instance of SpriteVisual using Compositor.CreateSpriteVisual.
  7. Set the Brush property of the SpriteVisual to the created effect.
  8. Add the SpriteVisual to the composition tree by using the Children property of a ContainerVisual.

Methods

Close Close Close Close

Closes the CompositionObject and releases system resources.

(Inherited from CompositionObject)
GetSourceParameter(String) GetSourceParameter(String) GetSourceParameter(String) GetSourceParameter(String)

Retrieves a CompositionBrush associated with a given CompositionEffectSourceParameter name.

SetSourceParameter(String, CompositionBrush) SetSourceParameter(String, CompositionBrush) SetSourceParameter(String, CompositionBrush) SetSourceParameter(String, CompositionBrush)

Associates a name declared using CompositionEffectSourceParameter to an effect source.

StartAnimation(String,CompositionAnimation) StartAnimation(String,CompositionAnimation) StartAnimation(String,CompositionAnimation) StartAnimation(String,CompositionAnimation)

Connects an animation with the specified property of the object and starts the animation.

(Inherited from CompositionObject)
StartAnimationGroup(ICompositionAnimationBase) StartAnimationGroup(ICompositionAnimationBase) StartAnimationGroup(ICompositionAnimationBase) StartAnimationGroup(ICompositionAnimationBase)

Starts an animation group.

The StartAnimationGroup method on CompositionObject lets you start CompositionAnimationGroup. All the animations in the group will be started at the same time on the object.

(Inherited from CompositionObject)
StopAnimation(String) StopAnimation(String) StopAnimation(String) StopAnimation(String)

Disconnects an animation from the specified property and stops the animation.

(Inherited from CompositionObject)
StopAnimationGroup(ICompositionAnimationBase) StopAnimationGroup(ICompositionAnimationBase) StopAnimationGroup(ICompositionAnimationBase) StopAnimationGroup(ICompositionAnimationBase)

Stops an animation group.

(Inherited from CompositionObject)
TryGetAnimationController(String) TryGetAnimationController(String) TryGetAnimationController(String) TryGetAnimationController(String)

Returns an AnimationController for the animation running on the specified property.

(Inherited from CompositionObject)

Properties

Comment Comment Comment Comment

A string to associate with the CompositionObject.

(Inherited from CompositionObject)
Compositor Compositor Compositor Compositor

The Compositor used to create this CompositionObject.

(Inherited from CompositionObject)
Dispatcher Dispatcher Dispatcher Dispatcher

The dispatcher for the CompositionObject.

(Inherited from CompositionObject)
DispatcherQueue DispatcherQueue DispatcherQueue DispatcherQueue

Gets the DispatcherQueue for the CompostionObject.

(Inherited from CompositionObject)
ImplicitAnimations ImplicitAnimations ImplicitAnimations ImplicitAnimations

The collection of implicit animations attached to this object.

(Inherited from CompositionObject)
Properties Properties Properties Properties

The collection of properties associated with the CompositionObject.

(Inherited from CompositionObject)

See Also