Exemple #1
0
        void CreateChildElement()
        {
            Uri localUri = new Uri("ms-appx:///Assets/StoreLogo.png");

            _imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor);
            CompositionImageOptions options = new CompositionImageOptions()
            {
                DecodeWidth  = 400,
                DecodeHeight = 400,
            };

            _image = _imageFactory.CreateImageFromUri(localUri, options);
            var visual = _compositor.CreateSpriteVisual();

            visual.Size  = new Vector2(400.0f, 400.0f);
            visual.Brush = _compositor.CreateSurfaceBrush(_image.Surface);
            _root.Children.InsertAtTop(visual);

            // If for some reason the image fails to load, replace the brush with
            // a red solid color.
            _image.ImageLoaded += (CompositionImage sender, CompositionImageLoadStatus status) =>
            {
                if (status != CompositionImageLoadStatus.Success)
                {
                    visual.Brush = _compositor.CreateColorBrush(Colors.Red);
                }
            };
        }
        private void Clock_Loaded(object sender, RoutedEventArgs e)
        {
            _root = Container.GetVisual();
            _compositor = _root.Compositor;

            // Background
            _background = _compositor.CreateSpriteVisual();
            _background.Size = new Vector2(200.0f, 200.0f);
            var _imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor);
            CompositionImageOptions options = new CompositionImageOptions()
            {
                DecodeWidth = 400,
                DecodeHeight = 400,
            };
            var _image = _imageFactory.CreateImageFromUri(FaceImage, options);
            _background.Brush = _compositor.CreateSurfaceBrush(_image.Surface);
            _root.Children.InsertAtTop(_background);

            // Hour Hand
            options = new CompositionImageOptions()
            {
                DecodeWidth = 72,
                DecodeHeight = 240,
            };

            _hourhand = _compositor.CreateSpriteVisual();
            _hourhand.Size = new Vector2(24.0f, 80.0f);
            _image = _imageFactory.CreateImageFromUri(HourHandImage, options);
            _hourhand.Brush = _compositor.CreateSurfaceBrush(_image.Surface);
            _hourhand.CenterPoint = new Vector3(12.0f, 70.0f, 0);
            _hourhand.Offset = new Vector3(88.0f, 30.0f, 0);
            _root.Children.InsertAtTop(_hourhand);

            // Minute Hand
            options = new CompositionImageOptions()
            {
                DecodeWidth = 48,
                DecodeHeight = 270,
            };
            _image = _imageFactory.CreateImageFromUri(MinuteHandImage, options);
            _minutehand = _compositor.CreateSpriteVisual();
            _minutehand.Size = new Vector2(16.0f, 90.0f);
            _minutehand.Brush = _compositor.CreateSurfaceBrush(_image.Surface);
            _minutehand.CenterPoint = new Vector3(8.0f, 85.0f, 0);
            _minutehand.Offset = new Vector3(92.0f, 15.0f, 0);
            _root.Children.InsertAtTop(_minutehand);

            SetHoursAndMinutes();

            // Second Hand
            _secondhand = _compositor.CreateSpriteVisual();
            _secondhand.Size = new Vector2(1.0f, 90.0f);
            _secondhand.Brush = _compositor.CreateColorBrush(Colors.Red);
            _secondhand.CenterPoint = new Vector3(0.5f, 90.0f, 0);
            _secondhand.Offset = new Vector3(99.5f, 10.0f, 0);
            _root.Children.InsertAtTop(_secondhand);
            _secondhand.RotationAngleInDegrees = (float)(int)DateTime.Now.TimeOfDay.TotalSeconds * 6;

            _timer.Start();
        }
        void CreateChildElement()
        {
            Uri localUri = new Uri("ms-appx:///Assets/StoreLogo.png");
            _imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor);
            CompositionImageOptions options = new CompositionImageOptions()
            {
                DecodeWidth = 400,
                DecodeHeight = 400,
            };

            _image = _imageFactory.CreateImageFromUri(localUri, options);
            var visual = _compositor.CreateSpriteVisual();
            visual.Size = new Vector2(400.0f, 400.0f);
            visual.Brush = _compositor.CreateSurfaceBrush(_image.Surface);
            _root.Children.InsertAtTop(visual);

            // If for some reason the image fails to load, replace the brush with
            // a red solid color.
            _image.ImageLoaded += (CompositionImage sender, CompositionImageLoadStatus status) =>
            {
                if (status != CompositionImageLoadStatus.Success)
                {
                    visual.Brush = _compositor.CreateColorBrush(Colors.Red);
                }
            };
        }
Exemple #4
0
    public void SetWindow(CoreWindow window)
    {
        Compositor      compositor = new Compositor();
        ContainerVisual root       = compositor.CreateContainerVisual();

        m_target      = compositor.CreateTargetForCurrentView();
        m_target.Root = root;

        Uri localUri     = new Uri("ms-appx:///Assets/StoreLogo.png");
        var imageFactory = CompositionImageFactory.CreateCompositionImageFactory(compositor);

        CompositionImageOptions options = new CompositionImageOptions()
        {
            DecodeWidth  = 400,
            DecodeHeight = 400,
        };

        var image  = imageFactory.CreateImageFromUri(localUri, options);
        var visual = compositor.CreateSpriteVisual();

        visual.Size  = new Vector2(400.0f, 400.0f);
        visual.Brush = compositor.CreateSurfaceBrush(image.Surface);
        root.Children.InsertAtTop(visual);

        image.ImageLoaded += (CompositionImage sender, CompositionImageLoadStatus status) =>
        {
            if (status != CompositionImageLoadStatus.Success)
            {
                visual.Brush = compositor.CreateColorBrush(Colors.Red);
            }
        };
    }
 static Photo()
 {
     s_thumbnailImageOptions = new CompositionImageOptions()
     {
         DecodeWidth  = 400,
         DecodeHeight = 400,
     };
 }
Exemple #6
0
 static Photo()
 {
     s_thumbnailImageOptions = new CompositionImageOptions()
     {
         DecodeWidth = 400,
         DecodeHeight = 400,
     };
 }
Exemple #7
0
        private void Clock_Loaded(object sender, RoutedEventArgs e)
        {
            _root       = Container.GetVisual();
            _compositor = _root.Compositor;

            // Background
            _background      = _compositor.CreateSpriteVisual();
            _background.Size = new Vector2(800.0f, 800.0f);
            var _imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor);
            var options       = new CompositionImageOptions()
            {
                DecodeWidth  = 740,
                DecodeHeight = 740
            };
            var _image = _imageFactory.CreateImageFromUri(FaceImage, options);

            _background.Brush = _compositor.CreateSurfaceBrush(_image.Surface);
            _root.Children.InsertAtTop(_background);

            // Hour Hand
            _hourhand             = _compositor.CreateSpriteVisual();
            _hourhand.Size        = new Vector2(800.0f, 800.0f);
            _image                = _imageFactory.CreateImageFromUri(HourHandImage, options);
            _hourhand.Brush       = _compositor.CreateSurfaceBrush(_image.Surface);
            _hourhand.Offset      = new Vector3(0.0f, 0.0f, 0);
            _hourhand.CenterPoint = new Vector3(400.0f, 400.0f, 0);
            _root.Children.InsertAtTop(_hourhand);

            // Minute Hand
            _minutehand             = _compositor.CreateSpriteVisual();
            _minutehand.Size        = new Vector2(800.0f, 800.0f);
            _image                  = _imageFactory.CreateImageFromUri(MinuteHandImage, options);
            _minutehand.Brush       = _compositor.CreateSurfaceBrush(_image.Surface);
            _minutehand.Offset      = new Vector3(0.0f, 0.0f, 0);
            _minutehand.CenterPoint = new Vector3(400.0f, 400.0f, 0);
            _root.Children.InsertAtTop(_minutehand);

            // Foreground
            _foreground       = _compositor.CreateSpriteVisual();
            _foreground.Size  = new Vector2(800.0f, 800.0f);
            _image            = _imageFactory.CreateImageFromUri(FrontImage, options);
            _foreground.Brush = _compositor.CreateSurfaceBrush(_image.Surface);
            _root.Children.InsertAtTop(_foreground);

            SetHoursAndMinutes();

            _timer.Start();
        }
        private void Clock_Loaded(object sender, RoutedEventArgs e)
        {
            _root = Container.GetVisual();
            _compositor = _root.Compositor;

            // Background
            _background = _compositor.CreateSpriteVisual();
            _background.Size = new Vector2(800.0f, 800.0f);
            var _imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor);
            var options = new CompositionImageOptions()
            {
                DecodeWidth = 740,
                DecodeHeight = 740
            };
            var _image = _imageFactory.CreateImageFromUri(FaceImage, options);
            _background.Brush = _compositor.CreateSurfaceBrush(_image.Surface);
            _root.Children.InsertAtTop(_background);

            // Hour Hand
            _hourhand = _compositor.CreateSpriteVisual();
            _hourhand.Size = new Vector2(800.0f, 800.0f);
            _image = _imageFactory.CreateImageFromUri(HourHandImage, options);
            _hourhand.Brush = _compositor.CreateSurfaceBrush(_image.Surface);
            _hourhand.Offset = new Vector3(0.0f, 0.0f, 0);
            _hourhand.CenterPoint = new Vector3(400.0f, 400.0f, 0);
            _root.Children.InsertAtTop(_hourhand);

            // Minute Hand
            _minutehand = _compositor.CreateSpriteVisual();
            _minutehand.Size = new Vector2(800.0f, 800.0f);
            _image = _imageFactory.CreateImageFromUri(MinuteHandImage, options);
            _minutehand.Brush = _compositor.CreateSurfaceBrush(_image.Surface);
            _minutehand.Offset = new Vector3(0.0f, 0.0f, 0);
            _minutehand.CenterPoint = new Vector3(400.0f, 400.0f, 0);
            _root.Children.InsertAtTop(_minutehand);

            // Foreground
            _foreground = _compositor.CreateSpriteVisual();
            _foreground.Size = new Vector2(800.0f, 800.0f);
            _image = _imageFactory.CreateImageFromUri(FrontImage, options);
            _foreground.Brush = _compositor.CreateSurfaceBrush(_image.Surface);
            _root.Children.InsertAtTop(_foreground);

            SetHoursAndMinutes();

            _timer.Start();
        }
Exemple #9
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);
        }
Exemple #11
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));
            }
        }
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _thumb = _compositor.CreateSpriteVisual();

            var _imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor);
            CompositionImageOptions options = new CompositionImageOptions()
            {
                DecodeWidth = 21,
                DecodeHeight = 36,
            };

            Uri thumbImageUri = new Uri("ms-appx:///Resources/Images/FaderThumb.png");
            var thumbImage = _imageFactory.CreateImageFromUri(thumbImageUri, options);

            _thumb.Brush = _compositor.CreateSurfaceBrush(thumbImage.Surface);
            _thumb.Size = new Vector2(21, 36);
            _thumb.Offset = new Vector3(-10, 0, 0);
            _root.Children.InsertAtTop(_thumb);
        }
        /// <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);
            
        }
Exemple #14
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 void Clock_Loaded(object sender, RoutedEventArgs e)
        {
            _root       = Container.GetVisual();
            _compositor = _root.Compositor;

            // Background
            _background      = _compositor.CreateSpriteVisual();
            _background.Size = new Vector2(200.0f, 200.0f);
            var _imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor);
            CompositionImageOptions options = new CompositionImageOptions()
            {
                DecodeWidth  = 400,
                DecodeHeight = 400,
            };
            var _image = _imageFactory.CreateImageFromUri(FaceImage, options);

            _background.Brush = _compositor.CreateSurfaceBrush(_image.Surface);
            _root.Children.InsertAtTop(_background);

            // Hour Hand
            options = new CompositionImageOptions()
            {
                DecodeWidth  = 72,
                DecodeHeight = 240,
            };

            _hourhand             = _compositor.CreateSpriteVisual();
            _hourhand.Size        = new Vector2(24.0f, 80.0f);
            _image                = _imageFactory.CreateImageFromUri(HourHandImage, options);
            _hourhand.Brush       = _compositor.CreateSurfaceBrush(_image.Surface);
            _hourhand.CenterPoint = new Vector3(12.0f, 70.0f, 0);
            _hourhand.Offset      = new Vector3(88.0f, 30.0f, 0);
            _root.Children.InsertAtTop(_hourhand);

            // Minute Hand
            options = new CompositionImageOptions()
            {
                DecodeWidth  = 48,
                DecodeHeight = 270,
            };
            _image                  = _imageFactory.CreateImageFromUri(MinuteHandImage, options);
            _minutehand             = _compositor.CreateSpriteVisual();
            _minutehand.Size        = new Vector2(16.0f, 90.0f);
            _minutehand.Brush       = _compositor.CreateSurfaceBrush(_image.Surface);
            _minutehand.CenterPoint = new Vector3(8.0f, 85.0f, 0);
            _minutehand.Offset      = new Vector3(92.0f, 15.0f, 0);
            _root.Children.InsertAtTop(_minutehand);

            SetHoursAndMinutes();

            // Second Hand
            _secondhand             = _compositor.CreateSpriteVisual();
            _secondhand.Size        = new Vector2(1.0f, 90.0f);
            _secondhand.Brush       = _compositor.CreateColorBrush(Colors.Red);
            _secondhand.CenterPoint = new Vector3(0.5f, 90.0f, 0);
            _secondhand.Offset      = new Vector3(99.5f, 10.0f, 0);
            _root.Children.InsertAtTop(_secondhand);
            _secondhand.RotationAngleInDegrees = (float)(int)DateTime.Now.TimeOfDay.TotalSeconds * 6;

            _timer.Start();
        }
        private static void OnStructureChanged(DependencyObject d)
        {
            Rating c = (Rating)d;

            if (c.EmptyImage == null)
            {
                c.EmptyImage = new Uri("ms-appx:///XamlBrewer.Uwp.RatingControl/Assets/defaultStar_empty.png");
            }

            if (c.FilledImage == null)
            {
                c.FilledImage = new Uri("ms-appx:///XamlBrewer.Uwp.RatingControl/Assets/defaultStar_full.png");
            }

            if ((c.StepFrequency <= 0) || (c.StepFrequency > 1))
            {
                c.StepFrequency = 1;
            }

            var panel = c.GetTemplateChild(ItemsPartName) as StackPanel;
            if (panel != null)
            {
                // Load images.
                var root = panel.GetVisual();
                var compositor = root.Compositor;
                var options = new CompositionImageOptions()
                {
                    DecodeWidth = c.ItemHeight,
                    DecodeHeight = c.ItemHeight
                };
                var imageFactory = CompositionImageFactory.CreateCompositionImageFactory(compositor);
                var image = imageFactory.CreateImageFromUri(c.EmptyImage, options);
                var emptyBrush = compositor.CreateSurfaceBrush(image.Surface);
                image = imageFactory.CreateImageFromUri(c.FilledImage, options);
                var fullBrush = compositor.CreateSurfaceBrush(image.Surface);

                var rightPadding = c.ItemPadding;
                c.Clips.Clear();

                for (int i = 0; i < c.Maximum; i++)
                {
                    if (i == c.Maximum - 1)
                    {
                        rightPadding = 0;
                    }

                    // Create grid.
                    var grid = new Grid
                    {
                        Height = c.ItemHeight,
                        Width = c.ItemHeight,
                        Margin = new Thickness(0, 0, rightPadding, 0)
                    };
                    panel.Children.Add(grid);
                    var gridRoot = grid.GetVisual();

                    // Empty image.
                    var spriteVisual = compositor.CreateSpriteVisual();
                    spriteVisual.Size = new Vector2(c.ItemHeight, c.ItemHeight);
                    gridRoot.Children.InsertAtTop(spriteVisual);
                    spriteVisual.Brush = emptyBrush;

                    // Filled image.
                    spriteVisual = compositor.CreateSpriteVisual();
                    spriteVisual.Size = new Vector2(c.ItemHeight, c.ItemHeight);
                    var clip = compositor.CreateInsetClip();
                    c.Clips.Add(clip);
                    spriteVisual.Clip = clip;
                    gridRoot.Children.InsertAtTop(spriteVisual);
                    spriteVisual.Brush = fullBrush;
                }
            }

            OnValueChanged(c);
        }