CompositionSurfaceBrush
CompositionSurfaceBrush
CompositionSurfaceBrush
CompositionSurfaceBrush
Class
Definition
Paints a SpriteVisual with pixels from an ICompositionSurface.
public : sealed class CompositionSurfaceBrush : CompositionBrush, ICompositionSurfaceBrush, ICompositionSurfaceBrush2public sealed class CompositionSurfaceBrush : CompositionBrush, ICompositionSurfaceBrush, ICompositionSurfaceBrush2Public NotInheritable Class CompositionSurfaceBrush Inherits CompositionBrush Implements ICompositionSurfaceBrush, ICompositionSurfaceBrush2// This API is not available in Javascript.
- Inheritance
-
CompositionSurfaceBrushCompositionSurfaceBrushCompositionSurfaceBrushCompositionSurfaceBrush
- Attributes
| Device family |
Windows 10 (introduced v10.0.10586.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v2)
|
Inherited Members
Inherited methods
Inherited properties
Examples
Draw an image asset onto a SpriteVisual
private SpriteVisual CreateImageVisual(ICompositionSurface imageSurface)
{
SpriteVisual imageVisual = _compositor.CreateSpriteVisual();
imageVisual.Size = new Vector2(300, 200);
CompositionSurfaceBrush imageBrush = _compositor.CreateSurfaceBrush();
imageBrush.Surface = imageSurface;
// specify CompositionStretch on SurfaceBrush and horizontal/vertical alignment
imageBrush.Stretch = CompositionStretch.UniformToFill;
imageBrush.HorizontalAlignmentRatio = 0.5f;
imageBrush.VerticalAlignmentRatio = 0.5f;
imageVisual.Brush = imageBrush;
return imageVisual;
}
Apply a custom scale transformation animation to a CompositionSurfaceBrush
private void AnimateBrushScale(SpriteVisual imageVisual)
{
CompositionSurfaceBrush imageBrush = (CompositionSurfaceBrush)imageVisual.Brush;
// set brush CenterPoint at the center of the content painted onto imageVisual
imageBrush.CenterPoint = imageVisual.Size / 2;
// set up scale keyframe animation
CompositionScopedBatch batch = _compositor.CreateScopedBatch(CompositionBatchTypes.Animation);
Vector2KeyFrameAnimation scaleAnimation = _compositor.CreateVector2KeyFrameAnimation();
scaleAnimation.InsertKeyFrame(1.0f, new Vector2(1.5f));
scaleAnimation.Duration = TimeSpan.FromMilliseconds(500);
// start animation on CompositionSurfaceBrush.Scale
imageBrush.StartAnimation("Scale", scaleAnimation);
// end animation batch and fire completion event
batch.End();
batch.Completed += ScaleAnimationBatch_Completed;
}
Remarks
The Stretch property, in conjunction with the HorizontalAlignmentRatio and VerticalAlignmentRatio properties, is used to specify the scale and positioning of the CompositionSurfaceBrush’s contents when painted onto a SpriteVisual.
CompositionSurfaceBrush also has the following properties that enable custom transformations:
- AnchorPoint
- CenterPoint
- Offset
- RotationAngle
- RotationAngleInDegrees
- Scale
- TransformMatrix
The order of transformation operations on a CompositionSurfaceBrush is as follows:
The content of the CompositionSurfaceBrush is stretched and aligned onto the SpriteVisual (see Stretch, HorizontalAlignmentRatio, and VerticalAlignmentRatio properties).
Any other transformation properties set on the CompositionSurfaceBrush are applied.
Custom transformations applied to a CompositionSurfaceBrush are therefore evaluated in the coordinate space of the SpriteVisual that the brush is painted onto. For example, setting an Offset of Vector2(100, 0) offsets the brush’s stretched and aligned contents by 100 units to the right relative to the left edge of the SpriteVisual it is painted onto.
Properties
AnchorPoint AnchorPoint AnchorPoint AnchorPoint
The point on the brush to be positioned at the brush's offset. Value is normalized with respect to the size of the SpriteVisual.
public : Vector2 AnchorPoint { get; set; }public Vector2 AnchorPoint { get; set; }Public ReadWrite Property AnchorPoint As Vector2// This API is not available in Javascript.
- Value
- Vector2 Vector2 Vector2 Vector2
The point on the brush to be positioned at the brush's offset. Value is normalized with respect to the size of the SpriteVisual.
| Device family |
Windows 10 Anniversary Edition (introduced v10.0.14393.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v3)
|
BitmapInterpolationMode BitmapInterpolationMode BitmapInterpolationMode BitmapInterpolationMode
Specifies the algorithm used for interpolating pixels from ICompositionSurface when they do not form a one-to-one mapping to pixels on SpriteVisual (as can happen under stretch, scale, rotation, and other transformations).
public : CompositionBitmapInterpolationMode BitmapInterpolationMode { get; set; }public CompositionBitmapInterpolationMode BitmapInterpolationMode { get; set; }Public ReadWrite Property BitmapInterpolationMode As CompositionBitmapInterpolationMode// This API is not available in Javascript.
- Value
- CompositionBitmapInterpolationMode CompositionBitmapInterpolationMode CompositionBitmapInterpolationMode CompositionBitmapInterpolationMode
Specifies the algorithm used for interpolating pixels from ICompositionSurface when they do not form a one-to-one mapping to pixels on SpriteVisual (as can happen under stretch, scale, rotation, and other transformations).
CenterPoint CenterPoint CenterPoint CenterPoint
The point about which the brush is rotated and scaled.
public : Vector2 CenterPoint { get; set; }public Vector2 CenterPoint { get; set; }Public ReadWrite Property CenterPoint As Vector2// This API is not available in Javascript.
- Value
- Vector2 Vector2 Vector2 Vector2
The point about which the brush is rotated and scaled.
| Device family |
Windows 10 Anniversary Edition (introduced v10.0.14393.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v3)
|
HorizontalAlignmentRatio HorizontalAlignmentRatio HorizontalAlignmentRatio HorizontalAlignmentRatio
Controls the positioning of the vertical axis of content with respect to the vertical axis of the SpriteVisual. The value is clamped from 0.0f to 1.0f with 0.0f representing the left vertical edge and 1.0f representing the right vertical edge of the SpriteVisual. By default this is set to 0.0f.
public : float HorizontalAlignmentRatio { get; set; }public float HorizontalAlignmentRatio { get; set; }Public ReadWrite Property HorizontalAlignmentRatio As float// This API is not available in Javascript.
- Value
- float float float float
The positioning of the vertical axis of content with respect to the vertical axis of the SpriteVisual. The value is clamped from 0.0f to 1.0f with 0.0f representing the left vertical edge and 1.0f representing the right vertical edge of the SpriteVisual. The default value is 0.5f.
Offset Offset Offset Offset
The offset of the brush relative to its SpriteVisual.
public : Vector2 Offset { get; set; }public Vector2 Offset { get; set; }Public ReadWrite Property Offset As Vector2// This API is not available in Javascript.
- Value
- Vector2 Vector2 Vector2 Vector2
The offset of the brush relative to its SpriteVisual.
| Device family |
Windows 10 Anniversary Edition (introduced v10.0.14393.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v3)
|
RotationAngle RotationAngle RotationAngle RotationAngle
The rotation angle, in radians, of the brush.
public : float RotationAngle { get; set; }public float RotationAngle { get; set; }Public ReadWrite Property RotationAngle As float// This API is not available in Javascript.
- Value
- float float float float
The rotation angle, in radians, of the brush.
| Device family |
Windows 10 Anniversary Edition (introduced v10.0.14393.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v3)
|
RotationAngleInDegrees RotationAngleInDegrees RotationAngleInDegrees RotationAngleInDegrees
The rotation angle, in degrees, of the brush.
public : float RotationAngleInDegrees { get; set; }public float RotationAngleInDegrees { get; set; }Public ReadWrite Property RotationAngleInDegrees As float// This API is not available in Javascript.
- Value
- float float float float
The rotation angle, in degrees, of the brush.
| Device family |
Windows 10 Anniversary Edition (introduced v10.0.14393.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v3)
|
Scale Scale Scale Scale
The scale to apply to the brush.
public : Vector2 Scale { get; set; }public Vector2 Scale { get; set; }Public ReadWrite Property Scale As Vector2// This API is not available in Javascript.
- Value
- Vector2 Vector2 Vector2 Vector2
The scale to apply to the brush.
| Device family |
Windows 10 Anniversary Edition (introduced v10.0.14393.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v3)
|
Stretch Stretch Stretch Stretch
Controls the scaling that is applied to the contents the ICompositionSurface with respect to the size of the SpriteVisual that is being painted.
public : CompositionStretch Stretch { get; set; }public CompositionStretch Stretch { get; set; }Public ReadWrite Property Stretch As CompositionStretch// This API is not available in Javascript.
Controls how the brush's content is scaled with respect to the size of the SpriteVisual it is painted onto.
If a CompositionSurfaceBrush is input as the Source to a CompositionNineGridBrush, the CompositionSurfaceBrush.Stretch property specifies how the center of the Nine-Grid is stretched with respect to the size of the SpriteVisual associated with the CompositionNineGridBrush.
Surface Surface Surface Surface
The ICompositionSurface associated with the CompositionSurfaceBrush.
public : ICompositionSurface Surface { get; set; }public ICompositionSurface Surface { get; set; }Public ReadWrite Property Surface As ICompositionSurface// This API is not available in Javascript.
The composition surface associated with the CompositionSurfaceBrush.
TransformMatrix TransformMatrix TransformMatrix TransformMatrix
The transformation matrix to apply to the brush.
public : Matrix3x2 TransformMatrix { get; set; }public Matrix3x2 TransformMatrix { get; set; }Public ReadWrite Property TransformMatrix As Matrix3x2// This API is not available in Javascript.
- Value
- Matrix3x2 Matrix3x2 Matrix3x2 Matrix3x2
The transformation matrix to apply to the brush.
| Device family |
Windows 10 Anniversary Edition (introduced v10.0.14393.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v3)
|
VerticalAlignmentRatio VerticalAlignmentRatio VerticalAlignmentRatio VerticalAlignmentRatio
Controls the positioning of the horizontal axis of content with respect to the horizontal axis of the SpriteVisual. The value is clamped from 0.0f to 1.0f with 0.0f representing the top horizontal edge and 1.0f representing the bottom horizontal edge of the SpriteVisual. The default value is 0.5f.
public : float VerticalAlignmentRatio { get; set; }public float VerticalAlignmentRatio { get; set; }Public ReadWrite Property VerticalAlignmentRatio As float// This API is not available in Javascript.
- Value
- float float float float
The positioning of the horizontal axis of content with respect to the horizontal axis of the SpriteVisual.