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);
        }
        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);
        }
        async void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
        {
            // get visuals from xaml object
            _touchAreaVisual = GetVisual(this.TouchArea);
            var imagePanelVisual = GetVisual(this.ImagePanel);

            // get compositor
            _compositor = imagePanelVisual.Compositor;

            // load the background image
            var image = _compositor.DefaultGraphicsDevice.CreateImageFromUri(new Uri("ms-appx:///Assets/White.png"));
            await image.CompleteLoadAsync();

            // todo: not sure why GaussianBlurEffect doesn't work??
            // Got a feeling it might have something to do with the Source setting, 
            // maybe it's just not supported yet?
            var effectDefination = new SaturationEffect // new GaussianBlurEffect
            {
                //BorderMode = EffectBorderMode.Soft,
                //BlurAmount = 5f,
                //Optimization = EffectOptimization.Quality,
                Source = new CompositionEffectSourceParameter("Overlay")
            };

            // create the actual effect
            var effectFactory = _compositor.CreateEffectFactory(effectDefination);
            var effect = effectFactory.CreateEffect();
            effect.SetSourceParameter("Overlay", image);

            // create the effect visual
            _effectVisual = _compositor.CreateEffectVisual();
            _effectVisual.Effect = effect;
            _effectVisual.Opacity = 0.8f;
            _effectVisual.Size = new Vector2((float)this.ImagePanel.ActualWidth, (float)this.ImagePanel.ActualHeight);

            // place the effect visual onto the UI
            imagePanelVisual.Children.InsertAtTop(_effectVisual);
        }
예제 #4
0
파일: Tile.cs 프로젝트: 678uhb/composition
        public void Dispose()
        {
            if (_rotationAnimator != null)
            {
                _rotationAnimator.Dispose();
                _rotationAnimator = null;
            }

            if (_offsetAnimator != null)
            {
                _offsetAnimator.Dispose();
                _offsetAnimator = null;
            }

            if (_selectedFrame != null)
            {
                _selectedFrame.Dispose();
                _selectedFrame = null;
            }

            if (_content != null)
            {
                _content.Dispose();
                _content = null;
            }

            if (_frame != null)
            {
                _frame.Dispose();
                _frame = null;
            }

            if (_saturationEffect != null)
            {
                _saturationEffect.Dispose();
                _saturationEffect = null;
            }

            // STEP4c: Clean-up effect animations.
            if (_saturationAnimator != null)
            {
                _saturationAnimator.Dispose();
                _saturationAnimator = null;
            }
        }