Aracılığıyla paylaş


CompositionEffectBrush Class

Definition

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

public ref class CompositionEffectBrush sealed : CompositionBrush
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 131072)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class CompositionEffectBrush final : CompositionBrush
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 131072)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class CompositionEffectBrush : CompositionBrush
Public NotInheritable Class CompositionEffectBrush
Inherits CompositionBrush
Inheritance
Object Platform::Object IInspectable CompositionObject CompositionBrush CompositionEffectBrush
Attributes

Windows requirements

Device family
Windows 10 (introduced in 10.0.10586.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v2.0)

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.

Properties

Comment

A string to associate with the CompositionObject.

(Inherited from CompositionObject)
Compositor

The Compositor used to create this CompositionObject.

(Inherited from CompositionObject)
Dispatcher

The dispatcher for the CompositionObject.

(Inherited from CompositionObject)
DispatcherQueue

Gets the DispatcherQueue for the CompostionObject.

(Inherited from CompositionObject)
ImplicitAnimations

The collection of implicit animations attached to this object.

(Inherited from CompositionObject)
Properties

The collection of properties associated with the CompositionObject.

(Inherited from CompositionObject)

Methods

Close()

Closes the CompositionObject and releases system resources.

(Inherited from CompositionObject)
ConnectAnimation(String, CompositionAnimation)

Connects and animation.

(Inherited from CompositionObject)
DisconnectAnimation(String)

Disconnects an animation.

(Inherited from CompositionObject)
Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

(Inherited from CompositionObject)
GetSourceParameter(String)

Retrieves a CompositionBrush associated with a given CompositionEffectSourceParameter name.

PopulatePropertyInfo(String, AnimationPropertyInfo)

Defines a property that can be animated.

(Inherited from CompositionObject)
SetSourceParameter(String, CompositionBrush)

Associates a name declared using CompositionEffectSourceParameter to an effect source.

StartAnimation(String, CompositionAnimation, AnimationController)

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

(Inherited from CompositionObject)
StartAnimation(String, CompositionAnimation)

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

(Inherited from CompositionObject)
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)

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

(Inherited from CompositionObject)
StopAnimationGroup(ICompositionAnimationBase)

Stops an animation group.

(Inherited from CompositionObject)
TryGetAnimationController(String)

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

(Inherited from CompositionObject)

Applies to

See also