Share via


CompositionMaskBrush Klasse

Definition

Zeichnet ein SpriteVisual mit einem CompositionBrush mit einer Deckkraftmaske, die darauf angewendet wird. Die Quelle der Deckkraftmaske kann ein beliebiger CompositionBrush vom Typ CompositionColorBrush, CompositionLinearGradientBrush, CompositionSurfaceBrush, CompositionEffectBrush oder compositionNineGridBrush sein. Die Deckkraftmaske muss als CompositionSurfaceBrush angegeben werden.

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

Windows-Anforderungen

Gerätefamilie
Windows 10 Anniversary Edition (eingeführt in 10.0.14393.0)
API contract
Windows.Foundation.UniversalApiContract (eingeführt in v3.0)

Beispiele

Wenden Sie eine star-förmige Maske auf ein Bild an.

private SpriteVisual CreateCircleImage(ICompositionSurface myImageSurface, ICompositionSurface myStarMaskSurface) 
{ 
  // Create SurfaceBrush with image surface and specify stretch and alignment 
  CompositionSurfaceBrush imageBrush = _compositor.CreateSurfaceBrush(myImageSurface); 
  imageBrush.HorizontalAlignmentRatio = 0.5f; 
  imageBrush.VerticalAlignmentRatio = 0.5f; 
  imageBrush.Stretch = CompositionStretch.UniformToFill; 

  // Create surface brush with opacity mask surface and specify stretch and alignment 
  CompositionSurfaceBrush starMaskBrush = _compositor.CreateSurfaceBrush(myStarMaskSurface); 
  starMaskBrush.Stretch = CompositionStretch.Uniform; 

  // SpriteVisual to be painted with masked content 
  SpriteVisual imageVisual = _compositor.CreateSpriteVisual(); 
  imageVisual.Size = new Vector2(200, 200); 

  // Create MaskBrush 
  CompositionMaskBrush maskBrush = _compositor.CreateMaskBrush(); 
  maskBrush.Source = imageBrush; // Set source to content that is to be masked 
  maskBrush.Mask = starMaskBrush; // Set mask to content that is the opacity mask 

  imageVisual.Brush = maskBrush; // Paint SpriteVisual with MaskBrush 

  return imageVisual;           
} 

Anwenden einer Deckkraftmaske auf vollfarbige Füllung, um eine Form zu erstellen; Animieren der Transformationseigenschaft für die Deckkraftmaske CompositionSurfaceBrush , um eine Farbblütenanimation zu erstellen

private void CreateCircleMaskSprite(ICompositionSurface myCircleMaskSurface, ICompositionSurface myImageSurface)
{
  // SpriteVisual to be painted by MaskBrush
  _circleVisual = _compositor.CreateSpriteVisual();
  _circleVisual.Size = MyContainerGrid.RenderSize.ToVector2();

  // SurfaceBrush w/ image as MaskBrush.Source
  CompositionSurfaceBrush imageBrush = _compositor.CreateSurfaceBrush(myImageSurface);
  imageBrush.Stretch = CompositionStretch.UniformToFill;

  // SurfaceBrush w/ opacity mask surface as MaskBrush.Mask
  CompositionSurfaceBrush circleBrush = _compositor.CreateSurfaceBrush(myCircleMaskSurface);

  // Specify stretch and transform properties to scale and position brush for initial state
  circleBrush.Stretch = CompositionStretch.Uniform;
  circleBrush.CenterPoint = _circleVisual.Size / 2;
  circleBrush.Scale = new Vector2(0.5f);

  // Create MaskBrush
  CompositionMaskBrush maskBrush = _compositor.CreateMaskBrush();
  maskBrush.Source = imageBrush;
  maskBrush.Mask = circleBrush;
  _circleVisual.Brush = maskBrush;

  // Set SpriteVisual as child of XAML Grid
  ElementCompositionPreview.SetElementChildVisual(MyContainerGrid, _circleVisual);
}

private void BloomAnimation()
{
  // Create KeyFrame Animation to target Scale transform on SurfaceBrush 
  Vector2KeyFrameAnimation scaleAnimation = _compositor.CreateVector2KeyFrameAnimation();
  scaleAnimation.InsertKeyFrame(1.0f, new Vector2(2));
  scaleAnimation.Duration = TimeSpan.FromMilliseconds(500);

  var maskBrush = (CompositionMaskBrush)_circleVisual.Brush;
  var surfaceBrush = (CompositionSurfaceBrush) maskBrush.Mask;

  // Animate the Scale on the circle opacity mask
  surfaceBrush.StartAnimation("Scale", scaleAnimation);      
}

Anwenden einer gerundeten Rechteckmaske zum Erstellen eines gerundeten Rechtecks mit Volltonfarbe, dessen Eckradius beim Ändern der Größe nicht erhöht wird (verwenden Sie CompositionNineGridBrush als Eingabe für eine CompositionMaskBrush ).

private SpriteVisual CreateMaskedRoundedRectVisual(ICompositionSurface myRoundedRectMaskSurface)
{
  // ColorBrush to be set as MaskBrush.Source
  CompositionColorBrush colorBrush = _compositor.CreateColorBrush(Colors.Blue);

  // SurfaceBrush w/ opacity mask surface
  CompositionSurfaceBrush roundedRectBrush = _compositor.CreateSurfaceBrush(myRoundedRectMaskSurface);
  roundedRectBrush.Stretch = CompositionStretch.Fill; // stretch for center of nine-grid

  // NineGridBrush w/ insets on opacity mask surface
  CompositionNineGridBrush ninegridBrush = _compositor.CreateNineGridBrush();
  ninegridBrush.Source = roundedRectBrush;
  ninegridBrush.SetInsets(_cornerRadius); // the radius, in pixels, of the corner as specified on my opacity mask surface 

  // Create MaskBrush
  CompositionMaskBrush maskBrush = _compositor.CreateMaskBrush();
  maskBrush.Source = colorBrush;
  maskBrush.Mask = ninegridBrush;

  // Paint SpriteVisual with MaskBrush
  SpriteVisual sprite = _compositor.CreateSpriteVisual();
  sprite.Size = new Vector2(300, 200);
  sprite.Brush = maskBrush;
  return sprite;

}

Hinweise

CompositionMaskBrush kann nicht als Quellparameter auf einen CompositionEffectBrush festgelegt werden. Wenn Sie einen IGraphicsEffect auf Ihre maskierten Inhalte anwenden möchten, verwenden Sie stattdessen ein CompositionEffectBrush-Element mit dem Zusammengesetzten Effekt .

Eigenschaften

Comment

Eine Zeichenfolge, die dem CompositionObject zugeordnet werden soll.

(Geerbt von CompositionObject)
Compositor

Der Compositor , der zum Erstellen dieses CompositionObject verwendet wird.

(Geerbt von CompositionObject)
Dispatcher

Der Dispatcher für das CompositionObject.

(Geerbt von CompositionObject)
DispatcherQueue

Ruft den DispatcherQueue für das CompostionObject ab.

(Geerbt von CompositionObject)
ImplicitAnimations

Die Auflistung impliziter Animationen, die diesem Objekt angefügt sind.

(Geerbt von CompositionObject)
Mask

Ein Pinsel, der die Deckkraftmaske enthält, mit der der Inhalt des Quellpinsels maskiert werden soll. Kann vom Typ CompositionSurfaceBrush oder CompositionNineGridBrush sein.

Properties

Die Auflistung von Eigenschaften, die dem CompositionObject zugeordnet sind.

(Geerbt von CompositionObject)
Source

Ein Pinsel, dessen Inhalt durch die Deckkraftmaske maskiert werden soll. Kann vom Typ CompositionSurfaceBrush, CompositionColorBrush oder CompositionNineGridBrush sein.

Methoden

Close()

Schließt das CompositionObject und gibt Systemressourcen frei.

(Geerbt von CompositionObject)
ConnectAnimation(String, CompositionAnimation)

Verbindet und Animation.

(Geerbt von CompositionObject)
DisconnectAnimation(String)

Trennt eine Animation.

(Geerbt von CompositionObject)
Dispose()

Führt anwendungsspezifische Aufgaben durch, die mit der Freigabe, der Zurückgabe oder dem Zurücksetzen von nicht verwalteten Ressourcen zusammenhängen.

(Geerbt von CompositionObject)
PopulatePropertyInfo(String, AnimationPropertyInfo)

Definiert eine Eigenschaft, die animiert werden kann.

(Geerbt von CompositionObject)
StartAnimation(String, CompositionAnimation)

Verbindet eine Animation mit der angegebenen Eigenschaft des Objekts und startet die Animation.

(Geerbt von CompositionObject)
StartAnimation(String, CompositionAnimation, AnimationController)

Verbindet eine Animation mit der angegebenen Eigenschaft des Objekts und startet die Animation.

(Geerbt von CompositionObject)
StartAnimationGroup(ICompositionAnimationBase)

Startet eine Animationsgruppe.

Mit der StartAnimationGroup-Methode für CompositionObject können Sie CompositionAnimationGroup starten. Alle Animationen in der Gruppe werden gleichzeitig für das Objekt gestartet.

(Geerbt von CompositionObject)
StopAnimation(String)

Trennt eine Animation von der angegebenen Eigenschaft und beendet die Animation.

(Geerbt von CompositionObject)
StopAnimationGroup(ICompositionAnimationBase)

Beendet eine Animationsgruppe.

(Geerbt von CompositionObject)
TryGetAnimationController(String)

Gibt einen AnimationController für die Animation zurück, die für die angegebene Eigenschaft ausgeführt wird.

(Geerbt von CompositionObject)

Gilt für:

Weitere Informationen