public void Mask() { // Create the graphics effect var graphicsEffect = new CompositeEffect { Mode = CanvasComposite.DestinationIn, Sources = { new CompositionEffectSourceParameter("image"), new Transform2DEffect { Name = "maskTransform", Source = new CompositionEffectSourceParameter("mask") } } }; // Compile the effect, specifying that the color should be modifiable. var effectFactory = _compositor.CreateEffectFactory( graphicsEffect, new[] { "maskTransform.TransformMatrix" }); // Create our effect and set its inputs var effect = effectFactory.CreateBrush(); CompositionSurfaceBrush profileBrush = _compositor.CreateSurfaceBrush(); LoadImage(profileBrush, new Uri("ms-appx:///Assets/dog.png")); effect.SetSourceParameter("image", profileBrush); CompositionSurfaceBrush circleMaskBrush = _compositor.CreateSurfaceBrush(); LoadImage(circleMaskBrush, new Uri("ms-appx:///Assets/CircleMask.png")); effect.SetSourceParameter("mask", circleMaskBrush); // Create a property set holding the scale we'll be animating var propertySet = _compositor.CreatePropertySet(); propertySet.InsertScalar("size", 0.0f); // Define the scale's animation var scaleAnimation = _compositor.CreateScalarKeyFrameAnimation(); var linearEasing = _compositor.CreateLinearEasingFunction(); scaleAnimation.InsertKeyFrame(0.0f, 0.0f, linearEasing); scaleAnimation.InsertKeyFrame(1.0f, 1.0f, linearEasing); scaleAnimation.Duration = TimeSpan.FromMilliseconds(5000); propertySet.StartAnimation("size", scaleAnimation); // Generate a Matrix4x4 from the size and bind it to the transform matrix var transformExpression = _compositor.CreateExpressionAnimation( "Matrix3x2(props.size, 0, 0, props.size, 0, 0)"); transformExpression.SetReferenceParameter("props", propertySet); effect.Properties.StartAnimation("maskTransform.TransformMatrix", transformExpression); // Create a visual with an instance of the effect var visual = _compositor.CreateSpriteVisual(); visual.Brush = effect; visual.Size = new Vector2(219, 229); _root.Children.InsertAtBottom(visual); }
public void Mask() { // Create the graphics effect var graphicsEffect = new CompositeEffect { Mode = CanvasComposite.DestinationIn, Sources = { new CompositionEffectSourceParameter("image"), new Transform2DEffect { Name = "maskTransform", Source = new CompositionEffectSourceParameter("mask") } } }; // Compile the effect, specifying that the color should be modifiable. var effectFactory = _compositor.CreateEffectFactory( graphicsEffect, new[] { "maskTransform.TransformMatrix" }); // Create our effect and set its inputs var effect = effectFactory.CreateEffect(); var graphicsDevice = _compositor.DefaultGraphicsDevice; var profilePicture = graphicsDevice.CreateImageFromUri( new Uri("ms-appx:///Assets/dog.png")); effect.SetSourceParameter("image", profilePicture); var circleMaskImage = graphicsDevice.CreateImageFromUri( new Uri("ms-appx:///Assets/CircleMask.png")); effect.SetSourceParameter("mask", circleMaskImage); // Create a property set holding the scale we'll be animating var propertySet = _compositor.CreatePropertySet(); propertySet.InsertScalar("size", 0.0f); // Define the scale's animation var scaleAnimation = _compositor.CreateScalarKeyFrameAnimation(); var linearEasing = _compositor.CreateLinearEasingFunction(); scaleAnimation.InsertKeyFrame(0.0f, 0.0f, linearEasing); scaleAnimation.InsertKeyFrame(1.0f, 1.0f, linearEasing); scaleAnimation.Duration = TimeSpan.FromMilliseconds(5000); propertySet.ConnectAnimation("size", scaleAnimation).Start(); // Generate a Matrix4x4 from the size and bind it to the transform matrix var transformExpression = _compositor.CreateExpressionAnimation( "Matrix3x2(props.size, 0, 0, props.size, 0, 0)"); transformExpression.SetReferenceParameter("props", propertySet); effect.Properties.ConnectAnimation("maskTransform.TransformMatrix", transformExpression); // Create a visual with an instance of the effect var visual = _compositor.CreateEffectVisual(); visual.Effect = effect; visual.Size = new Vector2(219, 229); _root.Children.InsertAtBottom(visual); }