private void LoadImage(Uri uri)
        {
            // Create CompositionSurfaceBrush
            var surfaceBrush = _compositor.CreateSurfaceBrush();

            // Create an image source to load
            CompositionImage imageSource = _imageFactory.CreateImageFromUri(uri);

            surfaceBrush.Surface = imageSource.Surface;

            _brush.SetSourceParameter("source", surfaceBrush);

            RotateHue(0);
        }
Example #2
0
        public async void animateBackGround(string img)
        {
            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
                blurredVisual.StartAnimation(nameof(Opacity), fadeOutAnimation);
                var image        = imageFactory.CreateImageFromUri(new Uri(img));
                var surfaceBrush = compositor.CreateSurfaceBrush(image.Surface);

                var effectBrush = effectFactory.CreateBrush();
                effectBrush.SetSourceParameter("source", surfaceBrush);

                blurredVisual.Brush       = effectBrush;
                blurredVisual.Size        = getBackgroundSize();
                blurredVisual.CenterPoint = new Vector3(getBackgroundSize().X / 2, getBackgroundSize().Y / 2, 0);
                ElementCompositionPreview.SetElementChildVisual(bgImage, blurredVisual);
                blurredVisual.StartAnimation(nameof(Opacity), fadeInAnimation);
            });
        }
Example #3
0
        /// <summary>
        /// Creates CompositionImages based on the URIs in ItemsSource
        /// </summary>
        private void CreateImages()
        {
            _images.Clear();
            var options = new CompositionImageOptions
            {
                DecodeWidth  = DecodeWidth,
                DecodeHeight = DecodeHeight
            };

            if ((ItemsSource == null) || !ItemsSource.Any())
            {
                return;
            }

            foreach (var uri in ItemsSource)
            {
                _images.Add(_imageFactory.CreateImageFromUri(uri, options));
            }
        }
Example #4
0
        /// <summary>
        /// Bind Compositon Images to the list which need to continue to the next page on navigation.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void FruitsList_ContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
        {
            //Get the clicked Item
            var item = args.Item as Item;

            //Get hold of the UIElement to bind items.
            var contentPanel = args.ItemContainer.ContentTemplateRoot as StackPanel;

            //Create Composition Image from data source
            var parentRectangle = _compositor.CreateContainerVisual();
            var rectangleColor  = _compositor.CreateSpriteVisual();

            rectangleColor.Size = new System.Numerics.Vector2(40, 40);

            //Use ImageFactory to load image from URI.
            try
            {
                CompositionImageFactory imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor);
                CompositionImageOptions options      = new CompositionImageOptions()
                {
                    DecodeWidth  = 160,
                    DecodeHeight = 160,
                };
                CompositionImage image = imageFactory.CreateImageFromUri(item.imageUri, options);
                rectangleColor.Brush = _compositor.CreateSurfaceBrush(image.Surface);
            }
            catch
            {
                rectangleColor.Brush = _compositor.CreateColorBrush(Windows.UI.Colors.Red);
            }

            //Bind Composition Image to UIElement - Rectangle in this case.
            Rectangle rectImage = contentPanel.FindName("imageItem") as Rectangle;

            parentRectangle.Children.InsertAtTop(rectangleColor);
            item.imageContainerVisual = parentRectangle;
            item.rectImage            = rectImage;
            ElementCompositionPreview.SetElementChildVisual(rectImage, parentRectangle);
        }
        private CompositionSurfaceBrush CreateBrushFromAsset(string name, out Size size)
        {
            Uri localUri = new Uri("ms-appx:///Assets/" + name);
            CompositionImageFactory surfaceFactory
                = CompositionImageFactory.CreateCompositionImageFactory(m_compositor);
            var image = surfaceFactory.CreateImageFromUri(localUri);

            bool isCompleted = false;
            var  waitHandle  = new AutoResetEvent(false);

            image.ImageLoaded += (CompositionImage sender, CompositionImageLoadStatus status) =>
            {
                isCompleted = true;
                waitHandle.Set();
            };

            while (!isCompleted)
            {
                waitHandle.WaitOne();
            }

            size = image.Size;
            return(m_compositor.CreateSurfaceBrush(image.Surface));
        }
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            // Initialize Composition UI infrastructure.
            _leftRoot   = LeftContainer.GetVisual();
            _middleRoot = MiddleContainer.GetVisual();
            _rightRoot  = RightContainer.GetVisual();
            _compositor = _leftRoot.Compositor;

            _imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor);

            // Hook the sprite visuals into the XAML visual tree.
            _leftSpriteVisual = _compositor.CreateSpriteVisual();
            var side = (float)Math.Min(LeftPresenter.ActualWidth, LeftPresenter.ActualHeight);

            _leftSpriteVisual.Size = new Vector2(side, side);
            _leftRoot.Children.InsertAtTop(_leftSpriteVisual);
            _middleSpriteVisual = _compositor.CreateSpriteVisual();
            side = (float)Math.Min(MiddlePresenter.ActualWidth, MiddlePresenter.ActualHeight);
            _middleSpriteVisual.Size = new Vector2(side, side);
            _middleRoot.Children.InsertAtTop(_middleSpriteVisual);
            _rightSpriteVisual = _compositor.CreateSpriteVisual();
            side = (float)Math.Min(RightPresenter.ActualWidth, RightPresenter.ActualHeight);
            _rightSpriteVisual.Size = new Vector2(side, side);
            _rightRoot.Children.InsertAtTop(_rightSpriteVisual);

            // Create CompositionSurfaceBrush
            _imageBrush = _compositor.CreateSurfaceBrush();

            // Create an image source to load
            var imageSource = _imageFactory.CreateImageFromUri(new Uri("ms-appx:///Assets/flowers.jpg"));

            _imageBrush.Surface = imageSource.Surface;

            // Create and apply the first effect.
            _firstEffect = new SaturationEffect
            {
                Name   = "firstEffect",
                Source = new CompositionEffectSourceParameter("source")
            };
            var firstEffectFactory = _compositor.CreateEffectFactory(_firstEffect, new[] { "firstEffect.Saturation" });

            _effectBrush1           = firstEffectFactory.CreateBrush();
            _leftSpriteVisual.Brush = _effectBrush1;

            // Create and apply the second effect.
            var secondEffect = new InvertEffect
            {
                Name   = "secondEffect",
                Source = new CompositionEffectSourceParameter("source")
            };
            var secondEffectFactory = _compositor.CreateEffectFactory(secondEffect);

            _effectBrush2             = secondEffectFactory.CreateBrush();
            _middleSpriteVisual.Brush = _effectBrush2;

            // Create and apply the combined effect.
            _combinedEffect = new InvertEffect
            {
                Name   = "chained",
                Source = _firstEffect
            };
            var combinedEffectFactory = _compositor.CreateEffectFactory(_combinedEffect, new[] { "firstEffect.Saturation" });

            _combinedBrush           = combinedEffectFactory.CreateBrush();
            _rightSpriteVisual.Brush = _combinedBrush;

            // Chain the brushes
            _effectBrush1.SetSourceParameter("source", _imageBrush);
            _effectBrush2.SetSourceParameter("source", _imageBrush);
            _combinedBrush.SetSourceParameter("source", _imageBrush);
        }