private void AddImageVisualForFollower(Uri imageUri, Vector3 offset, Vector2 size)
        {
            //Load profile image into a CompositionImage
            CompositionImage profileImage =
                _compositor.DefaultGraphicsDevice.CreateImageFromUri(imageUri);

            CompositionImage maskImage = _compositor.DefaultGraphicsDevice.CreateImageFromUri(new Uri("ms-appx:///Assets/CircularAlphaMaskInflated.png"));

            //Configure effect graph
            CompositeEffect maskCompositEffectDescription = new Microsoft.Graphics.Canvas.Effects.CompositeEffect();
            maskCompositEffectDescription.Sources.Add(new CompositionEffectSourceParameter("image"));
            maskCompositEffectDescription.Sources.Add(new CompositionEffectSourceParameter("maskImage"));
            maskCompositEffectDescription.Mode = Microsoft.Graphics.Canvas.CanvasComposite.DestinationIn;
            maskCompositEffectDescription.Name = "Mask";

            //Create an effect factory for the graph
            CompositionEffectFactory effectFactory = _compositor.CreateEffectFactory(maskCompositEffectDescription);

            //Create an instance of the effect and set source parameters
            CompositionEffect maskEffect = effectFactory.CreateEffect();
            maskEffect.SetSourceParameter("image", profileImage);
            maskEffect.SetSourceParameter("maskImage", maskImage);

            //Add main profile picture visual
            EffectVisual profileImageVisual = _compositor.CreateEffectVisual();
            profileImageVisual.Effect = maskEffect;
            profileImageVisual.Size = size;
            profileImageVisual.Offset = offset;

            //Add ImageVisual to tree
            _rootVisual.Children.InsertAtTop(profileImageVisual);
        }
        private void AddImageVisualForFollower(Uri imageUri, Vector3 offset, Vector2 size)
        {
            //Load profile image into a CompositionImage
            CompositionImage profileImage =
                _compositor.DefaultGraphicsDevice.CreateImageFromUri(imageUri);

            CompositionImage maskImage = _compositor.DefaultGraphicsDevice.CreateImageFromUri(new Uri("ms-appx:///Assets/CircularAlphaMaskInflated.png"));

            //Configure effect graph
            CompositeEffect maskCompositEffectDescription = new Microsoft.Graphics.Canvas.Effects.CompositeEffect();

            maskCompositEffectDescription.Sources.Add(new CompositionEffectSourceParameter("image"));
            maskCompositEffectDescription.Sources.Add(new CompositionEffectSourceParameter("maskImage"));
            maskCompositEffectDescription.Mode = Microsoft.Graphics.Canvas.CanvasComposite.DestinationIn;
            maskCompositEffectDescription.Name = "Mask";

            //Create an effect factory for the graph
            CompositionEffectFactory effectFactory = _compositor.CreateEffectFactory(maskCompositEffectDescription);

            //Create an instance of the effect and set source parameters
            CompositionEffect maskEffect = effectFactory.CreateEffect();

            maskEffect.SetSourceParameter("image", profileImage);
            maskEffect.SetSourceParameter("maskImage", maskImage);

            //Add main profile picture visual
            EffectVisual profileImageVisual = _compositor.CreateEffectVisual();

            profileImageVisual.Effect = maskEffect;
            profileImageVisual.Size   = size;
            profileImageVisual.Offset = offset;

            //Add ImageVisual to tree
            _rootVisual.Children.InsertAtTop(profileImageVisual);
        }
        private Visual MakeImageVisualforFollower(Uri imageUri, Vector2 size)
        {
            //Load profile image into a CompositionImage
            CompositionImage profileImage =
                _compositor.DefaultGraphicsDevice.CreateImageFromUri(imageUri);

            CompositionImage maskImage = _compositor.DefaultGraphicsDevice.CreateImageFromUri(new Uri("ms-appx:///Assets/CircularAlphaMaskInflated.png"));

            CompositeEffect maskComposite = new Microsoft.Graphics.Canvas.Effects.CompositeEffect();

            maskComposite.Sources.Add(new CompositionEffectSourceParameter("image"));
            maskComposite.Sources.Add(new CompositionEffectSourceParameter("maskImage"));
            maskComposite.Mode = Microsoft.Graphics.Canvas.CanvasComposite.DestinationIn;
            maskComposite.Name = "Mask";

            CompositionEffectFactory effectFactory = _compositor.CreateEffectFactory(maskComposite);

            CompositionEffect maskEffect = effectFactory.CreateEffect();

            maskEffect.SetSourceParameter("image", profileImage);
            maskEffect.SetSourceParameter("maskImage", maskImage);

            EffectVisual profileImageVisual = _compositor.CreateEffectVisual();

            profileImageVisual.Effect = maskEffect;
            profileImageVisual.Size   = size;

            return(profileImageVisual);
        }
Exemplo n.º 4
0
        private void GridView_ItemClick(object sender, ItemClickEventArgs e)
        {
            var rect  = (Rectangle)e.ClickedItem;
            var color = ((SolidColorBrush)rect.Fill).Color;



            var position    = rect.TransformToVisual(root).TransformPoint(new Point(0, 0));
            var spiteVisual = compositor.CreateSpriteVisual();

            container.Children.InsertAtTop(spiteVisual);

            spiteVisual.Size        = new System.Numerics.Vector2((float)rect.ActualWidth, (float)rect.ActualHeight);
            spiteVisual.Offset      = new System.Numerics.Vector3((float)position.X, (float)position.Y, 0);
            spiteVisual.AnchorPoint = new System.Numerics.Vector2(0.5f, 0.5f);


            var compositeEffect = new Microsoft.Graphics.Canvas.Effects.CompositeEffect()
            {
                Mode    = Microsoft.Graphics.Canvas.CanvasComposite.DestinationIn,
                Sources =
                {
                    new ColorSourceEffect()
                    {
                        Color = color
                    },
                    new CompositionEffectSourceParameter("mask")
                }
            };
            var factory        = compositor.CreateEffectFactory(compositeEffect);
            var compositeBursh = factory.CreateBrush();

            var surface = ImageLoader.Instance.LoadCircle(200, Colors.White);

            compositeBursh.SetSourceParameter("mask", surface.Brush);

            spiteVisual.Brush = compositeBursh;

            var oldDiameter = Math.Sqrt(rect.ActualHeight * rect.ActualHeight + rect.ActualWidth * rect.ActualWidth);
            var newDiameter = Math.Sqrt(root.ActualHeight * root.ActualHeight + root.ActualWidth * root.ActualWidth);
            //var oldDiameter = Math.Max(rect.ActualWidth, rect.ActualHeight);
            //var newDiameter = Math.Min(root.ActualWidth, root.ActualHeight);
            var scaleFactor = Math.Round(newDiameter / oldDiameter, MidpointRounding.AwayFromZero) * 2;


            var scaleAnimation = compositor.CreateScalarKeyFrameAnimation();
            var ease           = compositor.CreateCubicBezierEasingFunction(new System.Numerics.Vector2(0.1f, 0.94f), new System.Numerics.Vector2(0.39f, 0.97f));

            scaleAnimation.InsertKeyFrame(1f, (float)scaleFactor, ease);
            scaleAnimation.Duration = TimeSpan.FromMilliseconds(800);



            var batch = compositor.CreateScopedBatch(Windows.UI.Composition.CompositionBatchTypes.Animation);

            spiteVisual.StartAnimation("Scale.X", scaleAnimation);
            spiteVisual.StartAnimation("Scale.Y", scaleAnimation);

            batch.Completed += Batch_Completed;
            batch.End();
        }
        private Visual MakeImageVisualforFollower(Uri imageUri, Vector2 size)
        {
            //Load profile image into a CompositionImage
            CompositionImage profileImage =
                _compositor.DefaultGraphicsDevice.CreateImageFromUri(imageUri);

            CompositionImage maskImage = _compositor.DefaultGraphicsDevice.CreateImageFromUri(new Uri("ms-appx:///Assets/CircularAlphaMaskInflated.png"));

            CompositeEffect maskComposite = new Microsoft.Graphics.Canvas.Effects.CompositeEffect();
            maskComposite.Sources.Add(new CompositionEffectSourceParameter("image"));
            maskComposite.Sources.Add(new CompositionEffectSourceParameter("maskImage"));
            maskComposite.Mode = Microsoft.Graphics.Canvas.CanvasComposite.DestinationIn;
            maskComposite.Name = "Mask";

            CompositionEffectFactory effectFactory = _compositor.CreateEffectFactory(maskComposite);

            CompositionEffect maskEffect = effectFactory.CreateEffect();
            maskEffect.SetSourceParameter("image", profileImage);
            maskEffect.SetSourceParameter("maskImage", maskImage);

            EffectVisual profileImageVisual = _compositor.CreateEffectVisual();
            profileImageVisual.Effect = maskEffect;
            profileImageVisual.Size = size;

            return profileImageVisual;
        }