Beispiel #1
0
        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;

            var width  = (float)this.ImagePanel.ActualWidth;
            var height = (float)this.ImagePanel.ActualHeight;

            // load the background image
            var uri          = new Uri("ms-appx:///Assets/White.png");
            var imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor);
            var options      = new CompositionImageOptions
            {
                DecodeWidth  = (int)width,
                DecodeHeight = (int)height
            };
            var image = imageFactory.CreateImageFromUri(uri, options);

            // currently GaussianBlurEffect is not supported in Composition
            var effectDefination = new SaturationEffect // new GaussianBlurEffect
            {
                //BorderMode = EffectBorderMode.Soft,
                //BlurAmount = 5f,
                //Optimization = EffectOptimization.Quality,
                Source = new CompositionEffectSourceParameter("Overlay")
            };

            // create the actual effect
            var surfaceBrush  = _compositor.CreateSurfaceBrush(image.Surface);
            var effectFactory = _compositor.CreateEffectFactory(effectDefination);
            var effectBrush   = effectFactory.CreateBrush();

            effectBrush.SetSourceParameter("Overlay", surfaceBrush);

            // create the visual with the effect
            _visual         = _compositor.CreateSpriteVisual();
            _visual.Brush   = effectBrush;
            _visual.Opacity = 0.8f;
            _visual.Size    = new Vector2(width, height);

            // place the effect visual onto the UI
            imagePanelVisual.Children.InsertAtTop(_visual);
        }
        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;

            var width = (float)this.ImagePanel.ActualWidth;
            var height = (float)this.ImagePanel.ActualHeight;

            // load the background image
            var uri = new Uri("ms-appx:///Assets/White.png");
            var imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor);
            var options = new CompositionImageOptions
            {
                DecodeWidth = (int)width,
                DecodeHeight = (int)height
            };
            var image = imageFactory.CreateImageFromUri(uri, options);

            // currently GaussianBlurEffect is not supported in Composition
            var effectDefination = new SaturationEffect // new GaussianBlurEffect
            {
                //BorderMode = EffectBorderMode.Soft,
                //BlurAmount = 5f,
                //Optimization = EffectOptimization.Quality,
                Source = new CompositionEffectSourceParameter("Overlay")
            };

            // create the actual effect
            var surfaceBrush = _compositor.CreateSurfaceBrush(image.Surface);
            var effectFactory = _compositor.CreateEffectFactory(effectDefination);
            var effectBrush = effectFactory.CreateBrush();
            effectBrush.SetSourceParameter("Overlay", surfaceBrush);

            // create the visual with the effect
            _visual = _compositor.CreateSpriteVisual();
            _visual.Brush = effectBrush;
            _visual.Opacity = 0.8f;
            _visual.Size = new Vector2(width, height);

            // place the effect visual onto the UI
            imagePanelVisual.Children.InsertAtTop(_visual);
        }
        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);
        }