Skip to content

Latest commit

 

History

History
83 lines (55 loc) · 5.38 KB

compositioneffectbrush.md

File metadata and controls

83 lines (55 loc) · 5.38 KB
-api-id -api-type
T:Windows.UI.Composition.CompositionEffectBrush
winrt class

Windows.UI.Composition.CompositionEffectBrush

-description

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

-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.

-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); 
          

-see-also

Composition Brushes Overview, Composition Effects Overview, CompositionBrush, IClosable