示例#1
0
        public void ApplyCompositor()
        {
            var container = compositor.CreateContainerVisual();

            container.RotationAngle = 45;

            ElementCompositionPreview.SetElementChildVisual(theGrid, container);


            _LoadImageSurface = LoadedImageSurface.StartLoadFromUri(new Uri("ms-appx:///Assets/21.png"));
            _LoadImageSurface.LoadCompleted += (sender, args) =>
            {
                if (args.Status == LoadedImageSourceLoadStatus.Success)
                {
                    var brush = compositor.CreateSurfaceBrush(_LoadImageSurface);
                    brush.Stretch = CompositionStretch.Uniform;
                    var imageVisual = compositor.CreateSpriteVisual();
                    imageVisual.Size  = new Vector2(300, 300);
                    imageVisual.Brush = brush;
                    //imageVisual.RotationAngle = 45;
                    container.Children.InsertAtTop(imageVisual);
                }
                ;
            };
            //container.Compositor.CreateAmbientLight();
        }
示例#2
0
        private void CreateAcrylicEffectBrush_Click(object sender, RoutedEventArgs e)
        {
            if (Overlay.Background == null)
            {
                var compositor   = Window.Current.Compositor;
                var noiseSurface = LoadedImageSurface.StartLoadFromUri(new Uri("ms-appx:///Microsoft.UI.Xaml/Assets/NoiseAsset_256X256_PNG.png"));

                var acrylicFactory     = System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeMarshal.GetActivationFactory(typeof(AcrylicBrush));
                var privateApi         = (IAcrylicBrushStaticsPrivate)acrylicFactory;
                var acrylicEffectBrush = privateApi.CreateBackdropAcrylicEffectBrush(
                    compositor,
                    Color.FromArgb(0x44, 0x00, 0xFF, 0x00),
                    Colors.Transparent,
                    false);

                var noiseBrush = compositor.CreateSurfaceBrush(noiseSurface);
                noiseBrush.Stretch = CompositionStretch.None;

                acrylicEffectBrush.SetSourceParameter("Noise", noiseBrush);

                Overlay.Background = new WrapperEffectBrush(acrylicEffectBrush);
            }
            else
            {
                Overlay.Background = null;
            }
        }
示例#3
0
        private void LoadPlaceholderImage(Uri load)
        {
            _currentPosterUri = load;
            Action setSurface = () =>
            {
                _posterVisual.Brush = Window.Current.Compositor.CreateSurfaceBrush(_surface);
                if (PlayerService.Current.IsOpening || PlayerService.Current.IsClosed)
                {
                    _posterVisual.Opacity = 1.0f;
                }
            };

            if (_surface == null)
            {
                _surface = LoadedImageSurface.StartLoadFromUri(load);
                _surface.LoadCompleted += (o, l) =>
                {
                    setSurface();
                };
            }
            else
            {
                setSurface();
            }
        }
示例#4
0
        public void LoadImageFromPath(string path)
        {
            var compositor = Window.Current.Compositor;

            _surface = LoadedImageSurface.StartLoadFromUri(new Uri(path));
            _surface.LoadCompleted += Load_Completed;
        }
        protected override void OnConnected()
        {
            // return if Uri String is null or empty
            if (String.IsNullOrEmpty(ImageUriString))
            {
                return;
            }

            Compositor compositor = Window.Current.Compositor;

            // Use LoadedImageSurface API to get ICompositionSurface from image uri provided
            _surface = LoadedImageSurface.StartLoadFromUri(new Uri(ImageUriString));

            // Load Surface onto SurfaceBrush
            _surfaceBrush         = compositor.CreateSurfaceBrush(_surface);
            _surfaceBrush.Stretch = CompositionStretch.UniformToFill;

            // CompositionCapabilities: Are Tint+Temperature and Saturation supported?
            bool usingFallback = !CompositionCapabilities.GetForCurrentView().AreEffectsSupported();

            if (usingFallback)
            {
                // If Effects are not supported, Fallback to image without effects
                CompositionBrush = _surfaceBrush;
                return;
            }

            // Define Effect graph
            IGraphicsEffect graphicsEffect = new SaturationEffect
            {
                Name       = "Saturation",
                Saturation = 0.3f,
                Source     = new TemperatureAndTintEffect
                {
                    Name        = "TempAndTint",
                    Temperature = 0,
                    Source      = new CompositionEffectSourceParameter("Surface"),
                }
            };

            // Create EffectFactory and EffectBrush
            CompositionEffectFactory effectFactory = compositor.CreateEffectFactory(graphicsEffect, new[] { "TempAndTint.Temperature" });
            CompositionEffectBrush   effectBrush   = effectFactory.CreateBrush();

            effectBrush.SetSourceParameter("Surface", _surfaceBrush);

            // Set EffectBrush to paint Xaml UIElement
            CompositionBrush = effectBrush;

            // Trivial looping animation to demonstrate animated effect
            ScalarKeyFrameAnimation tempAnim = compositor.CreateScalarKeyFrameAnimation();

            tempAnim.InsertKeyFrame(0, 0);
            tempAnim.InsertKeyFrame(0.5f, 1f);
            tempAnim.InsertKeyFrame(1, 0);
            tempAnim.Duration          = TimeSpan.FromSeconds(5);
            tempAnim.IterationBehavior = Windows.UI.Composition.AnimationIterationBehavior.Forever;
            effectBrush.Properties.StartAnimation("TempAndTint.Temperature", tempAnim);
        }
        private CompositionMaskBrush CreateMaskBrush(int width, int height, Windows.UI.Color rateColor)
        {
            var _maskBrush = compositor.CreateMaskBrush();
            LoadedImageSurface loadedSurface = LoadedImageSurface.StartLoadFromUri(new Uri("ms-appx:///Assets/CircleMask.png"), new Windows.Foundation.Size(width, height));

            _maskBrush.Source = compositor.CreateColorBrush(rateColor);
            _maskBrush.Mask   = compositor.CreateSurfaceBrush(loadedSurface);
            return(_maskBrush);
        }
示例#7
0
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            var compositor = Window.Current.Compositor;

            _surface = LoadedImageSurface.StartLoadFromUri(new Uri("ms-appx:///Assets/webster-pass.png"));

            var backgroundBrush = compositor.CreateSurfaceBrush(_surface);

            backgroundBrush.Stretch = CompositionStretch.UniformToFill;

            var saturationEffect = new SaturationEffect
            {
                Saturation = 0.0f,
                Source     = new CompositionEffectSourceParameter("mySource")
            };

            var saturationEffectFactory = compositor.CreateEffectFactory(saturationEffect);

            var bwEffect = saturationEffectFactory.CreateBrush();

            bwEffect.SetSourceParameter("mySource", backgroundBrush);

            _backgroundVisual       = compositor.CreateSpriteVisual();
            _backgroundVisual.Brush = bwEffect;
            _backgroundVisual.Size  = RootElement.RenderSize.ToVector2();


            _containerVisual = compositor.CreateContainerVisual();
            _containerVisual.Children.InsertAtBottom(_backgroundVisual);
            ElementCompositionPreview.SetElementChildVisual(RootElement, _containerVisual);

            // Text
            _surfaceFactory = SurfaceFactory.GetSharedSurfaceFactoryForCompositor(compositor);

            _textSurface = _surfaceFactory.CreateTextSurface("Weston Pass");
            _textSurface.ForegroundColor = Color.FromArgb(50, 255, 255, 255);
            _textSurface.FontSize        = 150;
            var textSurfaceBrush = compositor.CreateSurfaceBrush(_textSurface.Surface);


            _textVisual      = compositor.CreateSpriteVisual();
            _textVisual.Size = _textSurface.Size.ToVector2();
            _textVisual.RotationAngleInDegrees = 45f;
            _textVisual.AnchorPoint            = new Vector2(0.5f);

            _textVisual.Brush = textSurfaceBrush;
            _textVisual.StartAnimation(nameof(Visual.Offset), CreateTextOffsetAnimation(
                                           new Vector3((float)RootElement.ActualWidth / 2, (float)RootElement.ActualWidth / 2, 0)));

            _containerVisual.Children.InsertAtTop(_textVisual);

            AddLighting();

            StartLightingAnimationTimer();
        }
示例#8
0
        private SpriteVisual CreateAcrylicNoiseVisual()
        {
            CompositionSurfaceBrush noiseBrush    = _compositor.CreateSurfaceBrush();
            LoadedImageSurface      loadedSurface = LoadedImageSurface.StartLoadFromUri(new Uri("ms-appx:///Assets/acrylicNoise.png"));

            noiseBrush.Surface = loadedSurface;

            SpriteVisual noiseVisual = _compositor.CreateSpriteVisual();

            return(noiseVisual);
        }
        private (CompositionBrush compositionBrush, CompositionSurfaceBrush compositionSurfaceBrush) CreateBrush(string imageName, Color color)
        {
            var compositor              = Window.Current.Compositor;
            var loadedSurface           = LoadedImageSurface.StartLoadFromUri(new Uri("ms-appx:///Assets/Images/" + imageName));
            var compositionSurfaceBrush = compositor.CreateSurfaceBrush();

            compositionSurfaceBrush.Surface = loadedSurface;
            var compositionBrush = CreateBrush(compositionSurfaceBrush, compositor.CreateColorBrush(color), BlendEffectMode.Lighten);

            return(compositionBrush, compositionSurfaceBrush);
        }
示例#10
0
        public void ValuesChanged(InteractionTracker sender, InteractionTrackerValuesChangedArgs args)
        {
            if (_indicator == null && ApiInfo.CanUseDirectComposition && (_tracker.Position.X > 0.0001f || _tracker.Position.X < -0.0001f) /*&& Math.Abs(e.Cumulative.Translation.X) >= 45*/)
            {
                var sprite = _visual.Compositor.CreateSpriteVisual();
                sprite.Size        = new Vector2(30, 30);
                sprite.CenterPoint = new Vector3(15);

                var surface = LoadedImageSurface.StartLoadFromUri(new Uri("ms-appx:///Assets/Images/Reply.png"));
                surface.LoadCompleted += (s, e) =>
                {
                    sprite.Brush = _visual.Compositor.CreateSurfaceBrush(s);
                };

                var ellipse = _visual.Compositor.CreateEllipseGeometry();
                ellipse.Radius = new Vector2(15);

                var ellipseShape = _visual.Compositor.CreateSpriteShape(ellipse);
                ellipseShape.FillBrush = _visual.Compositor.CreateColorBrush((Windows.UI.Color)App.Current.Resources["MessageServiceBackgroundColor"]);
                ellipseShape.Offset    = new Vector2(15);

                var shape = _visual.Compositor.CreateShapeVisual();
                shape.Shapes.Add(ellipseShape);
                shape.Size = new Vector2(30, 30);

                _indicator = _visual.Compositor.CreateContainerVisual();
                _indicator.Children.InsertAtBottom(shape);
                _indicator.Children.InsertAtTop(sprite);
                _indicator.Size        = new Vector2(30, 30);
                _indicator.CenterPoint = new Vector3(15);
                _indicator.Scale       = new Vector3();

                _container.Children.InsertAtTop(_indicator);

                //ElementCompositionPreview.SetElementChildVisual(this, _indicator);
                //ElementCompositionPreview.SetElementChildVisual(this, _container);
            }

            var offset = (_tracker.Position.X > 0 && !_reply) || (_tracker.Position.X <= 0 && !_forward) ? 0 : Math.Max(0, Math.Min(72, Math.Abs(_tracker.Position.X)));

            var abs     = Math.Abs(offset);
            var percent = abs / 72f;

            var width  = (float)ActualWidth;
            var height = (float)ActualHeight;

            if (_indicator != null)
            {
                _indicator.Offset  = new Vector3(_tracker.Position.X > 0 ? width - percent * 60 : -30 + percent * 55, (height - 30) / 2, 0);
                _indicator.Scale   = new Vector3(_tracker.Position.X > 0 ? 0.8f + percent * 0.2f : -(0.8f + percent * 0.2f), 0.8f + percent * 0.2f, 1);
                _indicator.Opacity = percent;
            }
        }
        private static void OnImageUriStringChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var brush = (ImageEffectBrush)d;

            // Unbox and update surface if CompositionBrush exists
            if (brush._surfaceBrush != null)
            {
                var newSurface = LoadedImageSurface.StartLoadFromUri(new Uri((String)e.NewValue));
                brush._surface = newSurface;
                brush._surfaceBrush.Surface = newSurface;
            }
        }
示例#12
0
        public static LayerTranslator CreateImageLayerTranslator(ImageLayerContext context)
        {
            if (!Transforms.TryCreateContainerVisualTransformChain(context, out var containerVisualRootNode, out var containerVisualContentNode))
            {
                // The layer is never visible.
                return(null);
            }

            var imageAsset = GetImageAsset(context);

            if (imageAsset is null)
            {
                return(null);
            }

            var content = context.ObjectFactory.CreateSpriteVisual();

            containerVisualContentNode.Children.Add(content);
            content.Size = new Sn.Vector2((float)imageAsset.Width, (float)imageAsset.Height);

            LoadedImageSurface surface;
            var imageSize = $"{imageAsset.Width}x{imageAsset.Height}";

            switch (imageAsset.ImageType)
            {
            case ImageAsset.ImageAssetType.Embedded:
                var embeddedImageAsset = (EmbeddedImageAsset)imageAsset;
                surface = LoadedImageSurface.StartLoadFromStream(embeddedImageAsset.Bytes);
                surface.SetName(imageAsset.Id);
                surface.SetDescription(context, $"Image: \"{embeddedImageAsset.Id}\" {embeddedImageAsset.Format} {imageSize}.");
                break;

            case ImageAsset.ImageAssetType.External:
                var externalImageAsset = (ExternalImageAsset)imageAsset;
                surface = LoadedImageSurface.StartLoadFromUri(new Uri($"file://localhost/{externalImageAsset.Path}{externalImageAsset.FileName}"));
                surface.SetName(externalImageAsset.FileName);
                var path = externalImageAsset.Path + externalImageAsset.FileName;
                surface.SetDescription(context, $"\"{path}\" {imageSize}.");
                context.Issues.ImageFileRequired(path);
                break;

            default:
                throw new InvalidOperationException();
            }

            var imageBrush = context.ObjectFactory.CreateSurfaceBrush(surface);

            content.Brush = imageBrush;

            return(new LayerTranslator.FromVisual(containerVisualRootNode));
        }
示例#13
0
        private void ApplyComposition()
        {
            var compositor = Window.Current.Compositor;

            var backVisual = ElementCompositionPreview.GetElementVisual(FancyGrid);

            //backVisual.Offset = new Vector3(100, 100, 0);

            ElementCompositionPreview.SetIsTranslationEnabled(FancyGrid, true);
            var fancyGridPropertySet = backVisual.Properties;

            fancyGridPropertySet.InsertVector3("Translation", new Vector3(100, 100, 0));

            backVisual.RotationAngleInDegrees = 45;
            backVisual.CenterPoint            = new Vector3((float)FancyGrid.ActualWidth / 2.0f, (float)FancyGrid.ActualHeight / 2.0f, 0);

            var sprite1 = compositor.CreateSpriteVisual();

            sprite1.Size   = new Vector2(50, 50);
            sprite1.Offset = new Vector3(50, 50, 0);
            sprite1.Brush  = compositor.CreateColorBrush(Colors.Green);

            var sprite2 = compositor.CreateSpriteVisual();

            sprite2.Size   = new Vector2(50, 50);
            sprite2.Offset = new Vector3(25, 25, 0);
            sprite2.Brush  = compositor.CreateColorBrush(Colors.Purple);


            var container = compositor.CreateContainerVisual();

            container.Children.InsertAtTop(sprite1);
            container.Children.InsertAtBottom(sprite2);

            ElementCompositionPreview.SetElementChildVisual(FancyGrid, container);

            _loadedImageSurface = LoadedImageSurface.StartLoadFromUri(new Uri("ms-appx:///Assets/JustEnoughBikes.jpg"));
            _loadedImageSurface.LoadCompleted += (sender, args) =>
            {
                if (args.Status == LoadedImageSourceLoadStatus.Success)
                {
                    var brush = compositor.CreateSurfaceBrush(_loadedImageSurface);
                    brush.Stretch = CompositionStretch.UniformToFill;
                    var imageVisual = compositor.CreateSpriteVisual();
                    imageVisual.Size  = new Vector2(400, 400);
                    imageVisual.Brush = brush;
                    container.Children.InsertAtTop(imageVisual);
                }
            };
        }
示例#14
0
        private Task <LoadedImageSurface> LoadImage(Uri uri, Size?size, CoreDispatcher dispatcher = null)
        {
            TaskCompletionSource <LoadedImageSurface> completionSource = new TaskCompletionSource <LoadedImageSurface>();
            LoadedImageSurface result = null;

            if (size.HasValue)
            {
                result = LoadedImageSurface.StartLoadFromUri(uri, size.Value);
            }
            else
            {
                result = LoadedImageSurface.StartLoadFromUri(uri);
            }

            TypedEventHandler <LoadedImageSurface, LoadedImageSourceLoadCompletedEventArgs> loadCompleteHandler = null;

            loadCompleteHandler = new TypedEventHandler <LoadedImageSurface, LoadedImageSourceLoadCompletedEventArgs>((sender, args) =>
            {
                sender.LoadCompleted -= loadCompleteHandler;
                if (dispatcher != null)
                {
                    _ = dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        if (args.Status == LoadedImageSourceLoadStatus.Success)
                        {
                            completionSource.SetResult(result);
                        }
                        else
                        {
                            completionSource.SetResult(null);
                        }
                    });
                }
                else
                {
                    if (args.Status == LoadedImageSourceLoadStatus.Success)
                    {
                        completionSource.SetResult(result);
                    }
                    else
                    {
                        completionSource.SetResult(null);
                    }
                }
            });

            result.LoadCompleted += loadCompleteHandler;

            return(completionSource.Task);
        }
示例#15
0
        public static LoadedImageSurface GetImageSurface(string assetName, Size imageSize)
        {
            Uri getImageUri()
            {
                if (SharedHelpers.IsInFrameworkPackage())
                {
                    return(new Uri("ms-resource://" + MUXCONTROLS_PACKAGE_NAME + "/Files/Microsoft.UI.Xaml/Assets/" + assetName + ".png"));
                }
                else
                {
                    return(new Uri("ms-resource:///Files/Microsoft.UI.Xaml/Assets/" + assetName + ".png"));
                }
            }

            return(LoadedImageSurface.StartLoadFromUri(getImageUri(), imageSize));
        }
示例#16
0
        /// <summary>
        /// Show Compositon effects on image
        /// </summary>
        /// <param name="imageURL">Image to effect</param>
        private void SetupComposition(Uri imageURL)
        {
            try
            {
                CompositionSurfaceBrush _imageBrush;

                Compositor _compositor = Window.Current.Compositor;

                _imageBrush         = _compositor.CreateSurfaceBrush();
                _imageBrush.Stretch = CompositionStretch.UniformToFill;


                LoadedImageSurface _loadedSurface = LoadedImageSurface.StartLoadFromUri(imageURL);
                _loadedSurface.LoadCompleted += _loadedSurface_LoadCompleted;
                _imageBrush.Surface           = _loadedSurface;

                // Saturate
                var saturationEffect = new SaturationEffect
                {
                    Saturation = 1,
                    Source     = new CompositionEffectSourceParameter("image")
                };
                var effectFactory = _compositor.CreateEffectFactory(saturationEffect);
                var effectBrush   = effectFactory.CreateBrush();
                effectBrush.SetSourceParameter("image", _imageBrush);

                // Blur
                var blurEffect = new GaussianBlurEffect
                {
                    BlurAmount = 8,
                    Source     = new CompositionEffectSourceParameter("image")
                };
                var effectFactory2 = _compositor.CreateEffectFactory(blurEffect);
                var effectBrush2   = effectFactory2.CreateBrush();
                effectBrush2.SetSourceParameter("image", effectBrush);

                _imageVisual       = _compositor.CreateSpriteVisual();
                _imageVisual.Brush = effectBrush2;
                _imageVisual.Size  = new Vector2(Convert.ToSingle(BackgroundContainer.ActualWidth), Convert.ToSingle(BackgroundContainer.ActualHeight));

                ElementCompositionPreview.SetElementChildVisual(BackgroundContainer, _imageVisual);
            }
            catch
            {
                // I guess it'll just look meh
            }
        }
        /// <summary>
        /// </summary>
        protected override void OnConnected()
        {
            var compositor = Window.Current.Compositor;

            // Load milky way image
            _surface = LoadedImageSurface.StartLoadFromUri(new Uri(App.PhotoCollection.ElementAt(4).Path));

            _surface.LoadCompleted += (s, startArgs) =>
            {
                if (startArgs.Status == LoadedImageSourceLoadStatus.Success)
                {
                    // Create blur effect
                    var brush = compositor.CreateSurfaceBrush(_surface);
                    brush.Stretch = CompositionStretch.UniformToFill;

                    IGraphicsEffect graphicsEffect = new GaussianBlurEffect
                    {
                        Name       = "Blur",
                        BlurAmount = 0,
                        Source     = new CompositionEffectSourceParameter("image")
                    };

                    var effectFactory = compositor.CreateEffectFactory(graphicsEffect, new[] { "Blur.BlurAmount" });
                    var effectBrush   = effectFactory.CreateBrush();
                    effectBrush.SetSourceParameter("image", brush);

                    // Composition Brush is what is being applied to the UI Element.
                    CompositionBrush = effectBrush;
                    PropertySet      = effectBrush.Properties;

                    // Animate the blur
                    var blurAnimation = compositor.CreateScalarKeyFrameAnimation();
                    blurAnimation.InsertKeyFrame(0, 0f);
                    blurAnimation.InsertKeyFrame(0.5f, 10.0f);
                    blurAnimation.InsertKeyFrame(1, 0);
                    blurAnimation.Duration          = TimeSpan.FromSeconds(4);
                    blurAnimation.IterationBehavior = AnimationIterationBehavior.Forever;

                    effectBrush.Properties.StartAnimation("Blur.BlurAmount", blurAnimation);
                }
            };
        }
示例#18
0
        private void LoadMazeRunnerVisual()
        {
            if (_mazeRunnerVisual != null)
            {
                _mazeRunnerVisual.Dispose();
            }

            _mazeRunnerVisual      = _compositor.CreateSpriteVisual();
            _mazeRunnerVisual.Size = new Vector2(_cellSize, _cellSize);

            LoadedImageSurface      loadedSurface = LoadedImageSurface.StartLoadFromUri(new Uri("ms-appx:///Assets/luna.png"), new Size(_cellSize, _cellSize));
            CompositionSurfaceBrush surfaceBrush  = _compositor.CreateSurfaceBrush();

            surfaceBrush.Surface    = loadedSurface;
            _mazeRunnerVisual.Brush = surfaceBrush;

            ElementCompositionPreview.SetElementChildVisual(MazeGrid, _mazeRunnerVisual);
            _mazeRunnerVisual.IsVisible = true;
            _mazeRunnerVisual.Opacity   = 1;
        }
        /// <summary>
        /// Initializes the Composition Brush.
        /// </summary>
        protected override void OnConnected()
        {
            // Delay creating composition resources until they're required.
            if (CompositionBrush == null && Source != null && Source is BitmapImage bitmap)
            {
                // Use LoadedImageSurface API to get ICompositionSurface from image uri provided
                // If UriSource is invalid, StartLoadFromUri will return a blank texture.
                _surface = LoadedImageSurface.StartLoadFromUri(bitmap.UriSource);

                // Load Surface onto SurfaceBrush
                _surfaceBrush         = Window.Current.Compositor.CreateSurfaceBrush(_surface);
                _surfaceBrush.Stretch = CompositionStretchFromStretch(Stretch);

                // Abort if effects aren't supported.
                if (!CompositionCapabilities.GetForCurrentView().AreEffectsSupported())
                {
                    // Just use image straight-up, if we don't support effects.
                    CompositionBrush = _surfaceBrush;
                    return;
                }

                var backdrop = Window.Current.Compositor.CreateBackdropBrush();

                // Use a Win2D invert affect applied to a CompositionBackdropBrush.
                var graphicsEffect = new BlendEffect
                {
                    Name       = "Invert",
                    Mode       = (BlendEffectMode)(int)Mode,
                    Background = new CompositionEffectSourceParameter("backdrop"),
                    Foreground = new CompositionEffectSourceParameter("image")
                };

                var effectFactory = Window.Current.Compositor.CreateEffectFactory(graphicsEffect);
                var effectBrush   = effectFactory.CreateBrush();

                effectBrush.SetSourceParameter("backdrop", backdrop);
                effectBrush.SetSourceParameter("image", _surfaceBrush);

                CompositionBrush = effectBrush;
            }
        }
        private (CompositionBrush, CompositionSurfaceBrush) CreateMaskedBrush(CompositionBrush source)
        {
            var compositor = Window.Current.Compositor;
            var effect     = new AlphaMaskEffect()
            {
                Source    = new CompositionEffectSourceParameter("Source"),
                AlphaMask = new CompositionEffectSourceParameter("Mask"),
            };

            var opacityMaskSurface = LoadedImageSurface.StartLoadFromUri(new Uri("ms-appx:///Assets/Images/mask.Png"));
            var opacityBrush       = Compositor.CreateSurfaceBrush(opacityMaskSurface);

            opacityBrush.Stretch = CompositionStretch.UniformToFill;

            var effectFactory    = compositor.CreateEffectFactory(effect);
            var compositionBrush = effectFactory.CreateBrush();

            compositionBrush.SetSourceParameter("Source", source);
            compositionBrush.SetSourceParameter("Mask", opacityBrush);
            return(compositionBrush, opacityBrush);
        }
        private static void OnImageSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var brush = (ImageBlendBrush)d;

            // Unbox and update surface if CompositionBrush exists
            if (brush._surfaceBrush != null)
            {
                // If UriSource is invalid, StartLoadFromUri will return a blank texture.
                var uri        = (e.NewValue as BitmapImage)?.UriSource ?? new Uri("ms-appx:///");
                var newSurface = LoadedImageSurface.StartLoadFromUri(uri);

                brush._surface = newSurface;
                brush._surfaceBrush.Surface = newSurface;
            }
            else
            {
                // If we didn't initially have a valid surface, we need to recreate our effect now.
                brush.OnDisconnected();
                brush.OnConnected();
            }
        }
示例#22
0
        protected override void OnConnected()
        {
            if (CompositionBrush == null)
            {
                var surface      = LoadedImageSurface.StartLoadFromUri(Source, new Size(480, 750));
                var surfaceBrush = Window.Current.Compositor.CreateSurfaceBrush(surface);
                surfaceBrush.Stretch = CompositionStretch.None;

                var borderEffect = new BorderEffect()
                {
                    Source  = new CompositionEffectSourceParameter("source"),
                    ExtendX = Microsoft.Graphics.Canvas.CanvasEdgeBehavior.Wrap,
                    ExtendY = Microsoft.Graphics.Canvas.CanvasEdgeBehavior.Wrap
                };

                var borderEffectFactory = Window.Current.Compositor.CreateEffectFactory(borderEffect);
                var borderEffectBrush   = borderEffectFactory.CreateBrush();
                borderEffectBrush.SetSourceParameter("source", surfaceBrush);

                CompositionBrush = borderEffectBrush;
            }
        }
示例#23
0
            public void LoadImage(Uri uri, Size?size = null)
            {
                lock (_lock)
                {
                    if (_surface != null)
                    {
                        _surface.LoadCompleted -= _surface_LoadCompleted;
                        _surface.Dispose();
                        _surface = null;
                    }

                    _loaded = false;
                    if (size.HasValue)
                    {
                        _surface = LoadedImageSurface.StartLoadFromUri(uri, size.Value);
                    }
                    else
                    {
                        _surface = LoadedImageSurface.StartLoadFromUri(uri);
                    }
                    _surface.LoadCompleted += _surface_LoadCompleted;
                }
            }
示例#24
0
        protected override void OnConnected()
        {
            Compositor compositor = Window.Current.Compositor;

            // CompositionCapabilities: Are Effects supported?
            bool usingFallback = !CompositionCapabilities.GetForCurrentView().AreEffectsSupported();

            FallbackColor = Color.FromArgb(100, 60, 60, 60);

            if (usingFallback)
            {
                // If Effects are not supported, use Fallback Solid Color
                CompositionBrush = compositor.CreateColorBrush(FallbackColor);
                return;
            }

            // Load NormalMap onto an ICompositionSurface using LoadedImageSurface
            _surface = LoadedImageSurface.StartLoadFromUri(new Uri("ms-appx:///Assets/Damaged_NormalMap.jpg"), new Size(400, 400));

            // Load Surface onto SurfaceBrush
            CompositionSurfaceBrush normalMap = compositor.CreateSurfaceBrush(_surface);

            normalMap.Stretch = CompositionStretch.Uniform;

            // Define Effect graph
            const float glassLightAmount = 0.5f;
            const float glassBlurAmount  = 0.95f;
            Color       tintColor        = Color.FromArgb(255, 128, 128, 128);

            var graphicsEffect = new ArithmeticCompositeEffect()
            {
                Name           = "LightComposite",
                Source1Amount  = 1,
                Source2Amount  = glassLightAmount,
                MultiplyAmount = 0,
                Source1        = new ArithmeticCompositeEffect()
                {
                    Name           = "BlurComposite",
                    Source1Amount  = 1 - glassBlurAmount,
                    Source2Amount  = glassBlurAmount,
                    MultiplyAmount = 0,
                    Source1        = new ColorSourceEffect()
                    {
                        Name  = "Tint",
                        Color = tintColor,
                    },
                    Source2 = new GaussianBlurEffect()
                    {
                        BlurAmount   = 20,
                        Source       = new CompositionEffectSourceParameter("Backdrop"),
                        Optimization = EffectOptimization.Balanced,
                        BorderMode   = EffectBorderMode.Hard,
                    },
                },
                Source2 = new SceneLightingEffect()
                {
                    AmbientAmount   = 0.15f,
                    DiffuseAmount   = 1,
                    SpecularAmount  = 0.1f,
                    NormalMapSource = new CompositionEffectSourceParameter("NormalMap")
                },
            };

            // Create EffectFactory and EffectBrush
            CompositionEffectFactory effectFactory = compositor.CreateEffectFactory(graphicsEffect);
            CompositionEffectBrush   effectBrush   = effectFactory.CreateBrush();

            // Create BackdropBrush
            CompositionBackdropBrush backdrop = compositor.CreateBackdropBrush();

            // Set Sources to Effect
            effectBrush.SetSourceParameter("NormalMap", normalMap);
            effectBrush.SetSourceParameter("Backdrop", backdrop);

            // Set EffectBrush as the brush that XamlCompBrushBase paints onto Xaml UIElement
            CompositionBrush = effectBrush;
        }
        /// <summary>
        /// Load the image and transform it to a composition brush or a XAML brush (depends of the UIStrategy)
        /// </summary>
        /// <param name="uri">the uri of the image to load</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        private async Task <bool> LoadImageBrushAsync(Uri uri)
        {
            if (DesignTimeHelpers.IsRunningInLegacyDesignerMode)
            {
                return(false);
            }

            if (_containerVisual == null || uri == null)
            {
                return(false);
            }

            await _flag.WaitAsync();

            try
            {
                bool isAnimated = IsAnimated;

                IsAnimated = false;

                if (_isImageSourceLoaded)
                {
                    for (int i = 0; i < _compositionChildren.Count; i++)
                    {
                        _compositionChildren[i].Brush = null;
                    }

                    _brushVisual?.Dispose();
                    _brushVisual = null;

                    _imageSurface?.Dispose();
                    _imageSurface = null;
                }

                _isImageSourceLoaded = false;

                var compositor = _containerVisual.Compositor;

                _imageSurface = LoadedImageSurface.StartLoadFromUri(uri);
                var loadCompletedSource = new TaskCompletionSource <bool>();
                _brushVisual = compositor.CreateSurfaceBrush(_imageSurface);

                _imageSurface.LoadCompleted += (s, e) =>
                {
                    if (e.Status == LoadedImageSourceLoadStatus.Success)
                    {
                        loadCompletedSource.SetResult(true);
                    }
                    else
                    {
                        loadCompletedSource.SetException(new ArgumentException("Image loading failed."));
                    }
                };

                await loadCompletedSource.Task;
                _imageSize = _imageSurface.DecodedPhysicalSize;

                _isImageSourceLoaded = true;

                RefreshContainerTile();

                RefreshImageSize(_imageSize.Width, _imageSize.Height);

                if (isAnimated)
                {
                    IsAnimated = true;
                }
            }
            finally
            {
                _flag.Release();
            }

            ImageLoaded?.Invoke(this, EventArgs.Empty);

            return(true);
        }
示例#26
0
        private void ConnectAcrylicBrush(bool useFallback)
        {
            DisconnectAcryilicBrush();

            bool isWindowed = BackgroundSource == CustomAcrylicBackgroundSource.Hostbackdrop;

            if (useFallback == false && PowerManager.EnergySaverStatus != EnergySaverStatus.On && !(UIViewSettings.GetForCurrentView().UserInteractionMode == UserInteractionMode.Touch && isWindowed))
            {
                ArithmeticCompositeEffect crossFadeEffect = new ArithmeticCompositeEffect
                {
                    MultiplyAmount = 0f,
                    Source1Amount  = 0.6f,
                    Source2Amount  = 0.4f,
                    Source1        = new ColorSourceEffect
                    {
                        Color = TintColor
                    },
                    Source2 = new ArithmeticCompositeEffect
                    {
                        MultiplyAmount = 0f,
                        Source1Amount  = sc_noiseOpacity,
                        Source2Amount  = 0.98f,
                        Source1        = new BorderEffect
                        {
                            Source  = new CompositionEffectSourceParameter("image"),
                            ExtendX = CanvasEdgeBehavior.Wrap,
                            ExtendY = CanvasEdgeBehavior.Wrap,
                        },
                        Source2 = new BlendEffect
                        {
                            Mode       = BlendEffectMode.Exclusion,
                            Foreground = new ColorSourceEffect
                            {
                                Color = Sc_exclusionColor
                            },
                            Background = new SaturationEffect
                            {
                                Saturation = sc_saturation,
                                Source     = new GaussianBlurEffect
                                {
                                    BlurAmount   = sc_blurRadius,
                                    BorderMode   = EffectBorderMode.Hard,
                                    Name         = "Blur",
                                    Optimization = EffectOptimization.Balanced,
                                    Source       = new CompositionEffectSourceParameter("source")
                                }
                            }
                        }
                    }
                };

                CompositionEffectFactory effectFactory = compositor.CreateEffectFactory(crossFadeEffect);
                effectBrush = effectFactory.CreateBrush();

                LoadedImageSurface imagesurface = LoadedImageSurface.StartLoadFromUri(new Uri("ms-appx:///UnitedCodebase/Assets/NoiseAsset_256X256_PNG.png"));

                CompositionSurfaceBrush imagebrush = compositor.CreateSurfaceBrush(imagesurface);
                imagebrush.Stretch = CompositionStretch.None;
                effectBrush.SetSourceParameter("image", imagebrush);

                if (BackgroundSource == CustomAcrylicBackgroundSource.Hostbackdrop)
                {
                    backdropBrush = compositor.CreateHostBackdropBrush();

                    effectBrush.SetSourceParameter("source", backdropBrush);
                }
                else
                {
                    backdropBrush = compositor.CreateBackdropBrush();

                    effectBrush.SetSourceParameter("source", backdropBrush);
                }

                CompositionBrush = effectBrush;
            }
            else
            {
                CompositionBrush = compositor.CreateColorBrush(FallbackColor);
            }
        }
示例#27
0
        private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            // Compositor
            _compositor = Window.Current.Compositor;

            // Load Image
            _imageSurface = LoadedImageSurface.StartLoadFromUri(new Uri("ms-appx:///Assets/webster-pass.png"));
            var backgroundBrush = _compositor.CreateSurfaceBrush(_imageSurface);

            backgroundBrush.Stretch = CompositionStretch.UniformToFill;

            // Apply Saturation Effect (Win2D)
            var saturationEffect = new SaturationEffect
            {
                Saturation = 0,
                Source     = new CompositionEffectSourceParameter("background")
            };

            var saturationEffectFactory = _compositor.CreateEffectFactory(saturationEffect);
            var saturationBrush         = saturationEffectFactory.CreateBrush();

            saturationBrush.SetSourceParameter("background", backgroundBrush);

            // Add background to visual tree
            _backgroundVisual       = _compositor.CreateSpriteVisual();
            _backgroundVisual.Brush = saturationBrush;
            _backgroundVisual.Size  = RootElement.RenderSize.ToVector2();

            _containerVisual = _compositor.CreateContainerVisual();
            _containerVisual.Children.InsertAtBottom(_backgroundVisual);
            ElementCompositionPreview.SetElementChildVisual(RootElement, _containerVisual);

            // Add Lighting
            _ambientLight           = _compositor.CreateAmbientLight();
            _ambientLight.Intensity = 1.5f;
            _ambientLight.Color     = Colors.Purple;
            _ambientLight.Targets.Add(_backgroundVisual);

            _pointLight1                 = _compositor.CreatePointLight();
            _pointLight1.Color           = Colors.Yellow;
            _pointLight1.CoordinateSpace = _containerVisual;
            _pointLight1.Targets.Add(_backgroundVisual);
            _pointLight1.Offset = new Vector3((float)RootElement.ActualWidth, (float)RootElement.ActualHeight * 0.25f, 300);

            _pointLight2                 = _compositor.CreatePointLight();
            _pointLight2.Color           = Colors.Green;
            _pointLight2.Intensity       = 2f;
            _pointLight2.CoordinateSpace = _containerVisual;
            _pointLight2.Targets.Add(_backgroundVisual);
            _pointLight2.Offset = new Vector3(0, (float)RootElement.ActualHeight * 0.75f, 300);

            // Animate Lights - Create expression template
            var offsetAnimation = Window.Current.Compositor.CreateVector3KeyFrameAnimation();

            offsetAnimation.Target = nameof(PointLight.Offset);
            offsetAnimation.InsertExpressionKeyFrame(1.0f, "this.FinalValue");
            offsetAnimation.Duration = TimeSpan.FromSeconds(10);

            // Animate Lights - create implicit animations
            _implicitOffsetAnimation = _compositor.CreateImplicitAnimationCollection();
            _implicitOffsetAnimation[nameof(Visual.Offset)] = offsetAnimation;

            _pointLight1.ImplicitAnimations = _implicitOffsetAnimation;
            _pointLight2.ImplicitAnimations = _implicitOffsetAnimation;

            // Animate Lights - create timer
            _lightTimer          = new DispatcherTimer();
            _lightTimer.Interval = TimeSpan.FromSeconds(10);
            _lightTimer.Tick    += LightTimerOnTick;
            _lightTimer.Start();

            // AnimateLights - initial move
            MoveLights();

            // Add Text (RobMikh.SurfaceFactory) Ø
            _surfaceFactory = SurfaceFactory.GetSharedSurfaceFactoryForCompositor(_compositor);
            _textSurface    = _surfaceFactory.CreateTextSurface("Hello Øredev!");
            _textSurface.ForegroundColor = Color.FromArgb(50, 255, 255, 255);
            _textSurface.FontSize        = 150;
            var textBrush = _compositor.CreateSurfaceBrush(_textSurface.Surface);

            _textVisual      = _compositor.CreateSpriteVisual();
            _textVisual.Size = _textSurface.Size.ToVector2();
            _textVisual.RotationAngleInDegrees = 45f;
            _textVisual.AnchorPoint            = new Vector2(0.5f);
            _textVisual.Brush = textBrush;
            _textVisual.StartAnimation(nameof(Visual.Offset), CreateTextAnimation());

            _containerVisual.Children.InsertAtTop(_textVisual);
        }
示例#28
0
        private void SetAllBitmaps(string topPath, Size?topSize, float?haloOffset, Size?haloSize, string middlePath, Size?middleSize, string bottomPath, Size?bottomSize)
        {
            if (!_isCompInitialized)
            {
                return;
            }

            LoadedImageSurface topSurface          = null;
            LoadedImageSurface topNormalSurface    = null;
            LoadedImageSurface haloSurface         = null;
            LoadedImageSurface middleSurface       = null;
            LoadedImageSurface middleNormalSurface = null;
            LoadedImageSurface bottomSurface       = null;
            LoadedImageSurface bottomNormalSurface = null;

            if (topPath != null)
            {
                string topNormalPath = topPath.Replace("_Color.png", "_Normal.png");
                string topHaloPath   = topPath.Replace("_Color.png", "_Halo.png");

                if (topSize.HasValue)
                {
                    _topVisual.Size  = topSize.Value.ToVector2();
                    topSurface       = LoadedImageSurface.StartLoadFromUri(new Uri(topPath), topSize.Value);
                    topNormalSurface = LoadedImageSurface.StartLoadFromUri(new Uri(topNormalPath), topSize.Value);
                }
                else
                {
                    topSurface       = LoadedImageSurface.StartLoadFromUri(new Uri(topPath));
                    topNormalSurface = LoadedImageSurface.StartLoadFromUri(new Uri(topNormalPath));
                }
                if (haloSize.HasValue)
                {
                    _haloVisual.Size = haloSize.Value.ToVector2();
                    haloSurface      = LoadedImageSurface.StartLoadFromUri(new Uri(topHaloPath), haloSize.Value);
                }
                else
                {
                    haloSurface = LoadedImageSurface.StartLoadFromUri(new Uri(topHaloPath));
                }

                if (!_isCompInitialized)
                {
                    return;
                }
            }

            if (middlePath != null)
            {
                string middleNormalPath = middlePath.Replace("_Color.png", "_Normal.png");

                if (middleSize.HasValue)
                {
                    _middleVisual.Size  = middleSize.Value.ToVector2();
                    middleSurface       = LoadedImageSurface.StartLoadFromUri(new Uri(middlePath), middleSize.Value);
                    middleNormalSurface = LoadedImageSurface.StartLoadFromUri(new Uri(middleNormalPath), middleSize.Value);
                }
                else
                {
                    middleSurface       = LoadedImageSurface.StartLoadFromUri(new Uri(middlePath));
                    middleNormalSurface = LoadedImageSurface.StartLoadFromUri(new Uri(middleNormalPath));
                }

                if (!_isCompInitialized)
                {
                    return;
                }
            }

            if (bottomPath != null)
            {
                string bottomNormalPath = bottomPath.Replace("_Color.png", "_Normal.png");

                if (bottomSize.HasValue)
                {
                    _bottomVisual.Size  = bottomSize.Value.ToVector2();
                    bottomSurface       = LoadedImageSurface.StartLoadFromUri(new Uri(bottomPath), bottomSize.Value);
                    bottomNormalSurface = LoadedImageSurface.StartLoadFromUri(new Uri(bottomNormalPath), bottomSize.Value);
                }
                else
                {
                    bottomSurface       = LoadedImageSurface.StartLoadFromUri(new Uri(bottomPath));
                    bottomNormalSurface = LoadedImageSurface.StartLoadFromUri(new Uri(bottomNormalPath));
                }

                if (!_isCompInitialized)
                {
                    return;
                }
            }

            var compositor = Window.Current.Compositor;

            if (topSurface != null && topNormalSurface != null)
            {
                _topColorImage   = topSurface;
                _topNormalImage  = topNormalSurface;
                _topVisual.Brush = CreateNormalMapBrush(compositor, _topNormalImage, _topColorImage);
            }

            if (haloSurface != null)
            {
                _haloColorImage = haloSurface;
                // The halo color image being its own normal image is deliberate
                _haloVisual.Brush = CreateNormalMapBrush(compositor, _haloColorImage, _haloColorImage);
            }

            if (middleSurface != null && middleNormalSurface != null)
            {
                _middleColorImage   = middleSurface;
                _middleNormalImage  = middleNormalSurface;
                _middleVisual.Brush = CreateNormalMapBrush(compositor, _middleNormalImage, _middleColorImage);
            }

            if (bottomSurface != null && bottomNormalSurface != null)
            {
                _bottomColorImage   = bottomSurface;
                _bottomNormalImage  = bottomNormalSurface;
                _bottomVisual.Brush = CreateNormalMapBrush(compositor, _bottomNormalImage, _bottomColorImage);
            }

            if (haloOffset.HasValue)
            {
                _haloOffset = haloOffset.Value;
            }
            LayoutVisuals(_assetsLoaded);
        }
示例#29
0
        public MainPage()
        {
            this.InitializeComponent();

            ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen;

            VersionTextBlock.Text = GetAppVersion();

            GazeInput.DwellFeedbackCompleteBrush = new SolidColorBrush(Colors.Transparent);

            _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;

            LoadedImageSurface loadedSurface = LoadedImageSurface.StartLoadFromUri(new Uri("ms-appx:///Assets/BorderDot.png"), new Size(_cellSize, _cellSize));

            _breadCrumbBrush         = _compositor.CreateSurfaceBrush();
            _breadCrumbBrush.Surface = loadedSurface;

            _numRows = MIN_ROWS;

            _mazeRunner = new Image
            {
                Source            = new BitmapImage(new Uri(this.BaseUri, "/Assets/luna.png")),
                VerticalAlignment = VerticalAlignment.Center
            };

            _mazeEnd = new Image
            {
                Source            = new BitmapImage(new Uri(this.BaseUri, "/Assets/doghouse.png")),
                VerticalAlignment = VerticalAlignment.Center
            };

            _mazeComplete = new Image
            {
                Source            = new BitmapImage(new Uri(this.BaseUri, "/Assets/dogInHouse.png")),
                VerticalAlignment = VerticalAlignment.Center
            };

            _newSolidBorderThickness = new Thickness(_borderThickness);
            _newButtonStyle          = (Style)this.Resources["MazeCellStyle"];

            _mazeCreator = Creator.GetCreator();

            _solutionTimer          = new DispatcherTimer();
            _solutionTimer.Interval = TimeSpan.FromSeconds(0.1);
            _solutionTimer.Tick    += OnSolutionTimerTick;

            _cellCreationTimer          = new DispatcherTimer();
            _cellCreationTimer.Interval = TimeSpan.FromMilliseconds(50);
            _cellCreationTimer.Tick    += OnCellCreationTimer_Tick;

            _openCellTimer          = new DispatcherTimer();
            _openCellTimer.Interval = TimeSpan.FromMilliseconds(50);
            _openCellTimer.Tick    += OnOpenCellTimer_Tick;

            _mazeCells   = new List <Point>();
            _breadCrumbs = new List <Point>();

            Loaded += MainPage_Loaded;

            CoreWindow.GetForCurrentThread().KeyDown += new Windows.Foundation.TypedEventHandler <CoreWindow, KeyEventArgs>(delegate(CoreWindow sender, KeyEventArgs args) {
                GazeInput.GetGazePointer(this).Click();
            });

            var sharedSettings = new ValueSet();

            GazeSettingsHelper.RetrieveSharedSettings(sharedSettings).Completed = new AsyncActionCompletedHandler((asyncInfo, asyncStatus) =>
            {
                GazeInput.LoadSettings(sharedSettings);
            });
        }
示例#30
0
        protected override void OnConnected()
        {
            if (DesignMode.DesignModeEnabled)
            {
                return;
            }
            compositor = ElementCompositionPreview.GetElementVisual(Window.Current.Content as UIElement).Compositor;
            var tintOpacity = Convert.ToSingle(TintOpacity);

            if (tintOpacity < 0f)
            {
                tintOpacity = 0f;
            }
            if (tintOpacity > 1f)
            {
                tintOpacity = 1f;
            }
            var arithmeticEffect = new ArithmeticCompositeEffect()
            {
                Name           = "arithmetic",
                MultiplyAmount = 0,
                Source1Amount  = 1f - tintOpacity,
                Source2Amount  = tintOpacity,
                Source1        = new ArithmeticCompositeEffect()
                {
                    MultiplyAmount = 0f,
                    Source1Amount  = 0.95f,
                    Source2Amount  = 0.05f,
                    Source1        = new GaussianBlurEffect()
                    {
                        Name         = "blur",
                        BlurAmount   = Convert.ToSingle(BlurAmount),
                        BorderMode   = EffectBorderMode.Hard,
                        Optimization = EffectOptimization.Balanced,
                        Source       = new CompositionEffectSourceParameter("source"),
                    },
                    Source2 = new BorderEffect()
                    {
                        Source  = new CompositionEffectSourceParameter("image"),
                        ExtendX = CanvasEdgeBehavior.Wrap,
                        ExtendY = CanvasEdgeBehavior.Wrap,
                    }
                },
                Source2 = new ColorSourceEffect()
                {
                    Name  = "tintcolor",
                    Color = TintColor
                }
            };

            Brush = compositor.CreateEffectFactory(arithmeticEffect, new[] { "arithmetic.Source1Amount", "arithmetic.Source2Amount", "tintcolor.Color" }).CreateBrush();

            var imagesurface = LoadedImageSurface.StartLoadFromUri(new Uri("ms-appx:///FluentDesignSystem/Sketch/SketchTexture.jpg"));

            var imagebrush = compositor.CreateSurfaceBrush(imagesurface);

            imagebrush.Stretch = CompositionStretch.None;
            Brush.SetSourceParameter("image", imagebrush);

            switch (BackgroundSource)
            {
            case AcrylicBackgroundSource.Backdrop:
                Brush.SetSourceParameter("source", compositor.CreateBackdropBrush());
                break;

            case AcrylicBackgroundSource.Hostbackdrop:
                Brush.SetSourceParameter("source", compositor.CreateHostBackdropBrush());
                break;
            }

            CompositionBrush = Brush;

            var line = compositor.CreateLinearEasingFunction();

            TintOpacityFillAnimation = compositor.CreateScalarKeyFrameAnimation();
            TintOpacityFillAnimation.InsertExpressionKeyFrame(0f, "TintOpacity", line);
            TintOpacityFillAnimation.InsertKeyFrame(1f, 1f, line);
            TintOpacityFillAnimation.Duration = TimeSpan.FromSeconds(0.1d);
            TintOpacityFillAnimation.Target   = "arithmetic.Source2Amount";

            HostOpacityZeroAnimation = compositor.CreateScalarKeyFrameAnimation();
            HostOpacityZeroAnimation.InsertExpressionKeyFrame(0f, "1f - TintOpacity", line);
            HostOpacityZeroAnimation.InsertKeyFrame(1f, 0f, line);
            HostOpacityZeroAnimation.Duration = TimeSpan.FromSeconds(0.1d);
            HostOpacityZeroAnimation.Target   = "arithmetic.Source1Amount";

            TintToFallBackAnimation = compositor.CreateColorKeyFrameAnimation();
            TintToFallBackAnimation.InsertKeyFrame(0f, TintColor, line);
            TintToFallBackAnimation.InsertKeyFrame(1f, FallbackColor, line);
            TintToFallBackAnimation.Duration = TimeSpan.FromSeconds(0.1d);
            TintToFallBackAnimation.Target   = "tintcolor.Color";

            //Window.Current.Activated += Current_Activated;
            //Window.Current.VisibilityChanged += Current_VisibilityChanged;
            CoreWindow.GetForCurrentThread().Activated         += AcrylicBrush_Activated;
            CoreWindow.GetForCurrentThread().VisibilityChanged += AcrylicBrush_VisibilityChanged;
        }