当前位置: 首页>>代码示例>>C#>>正文


C# Compositor.CreateSurfaceBrush方法代码示例

本文整理汇总了C#中Compositor.CreateSurfaceBrush方法的典型用法代码示例。如果您正苦于以下问题:C# Compositor.CreateSurfaceBrush方法的具体用法?C# Compositor.CreateSurfaceBrush怎么用?C# Compositor.CreateSurfaceBrush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Compositor的用法示例。


在下文中一共展示了Compositor.CreateSurfaceBrush方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Clock_Loaded

        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();
        }
开发者ID:x01673,项目名称:UWP-Composition-API-Clock,代码行数:60,代码来源:ImageClock.xaml.cs

示例2: SamplePage_Loaded

        private void SamplePage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            // Get backing visual from shadow container and interop compositor
            _shadowContainer = ElementCompositionPreview.GetElementVisual(ShadowContainer);
            _compositor = _shadowContainer.Compositor;

            // Get CompositionImage, its sprite visual
            _image = VisualTreeHelperExtensions.GetFirstDescendantOfType<CompositionImage>(ShadowContainer);
            _imageVisual = _image.SpriteVisual;

            // Load mask asset onto surface using helpers in SamplesCommon
            _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor);
            _imageMaskSurface = _imageLoader.CreateCircleSurface(200, Colors.White);

            // Create surface brush for mask
            CompositionSurfaceBrush mask = _compositor.CreateSurfaceBrush();
            mask.Surface = _imageMaskSurface.Surface;
            
            // Get surface brush from composition image
            CompositionSurfaceBrush source = _image.SurfaceBrush as CompositionSurfaceBrush;

            // Create mask brush for toggle mask functionality
            _maskBrush = _compositor.CreateMaskBrush();
            _maskBrush.Mask = mask;
            _maskBrush.Source = source;

            // Initialize toggle mask
            _isMaskEnabled = false;
        }
开发者ID:clarkezone,项目名称:composition,代码行数:29,代码来源:ShadowPlayground.xaml.cs

示例3: Clock_Loaded

        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();
        }
开发者ID:x01673,项目名称:UWP-Composition-API-Clock,代码行数:47,代码来源:SillyWalkerClock.xaml.cs

示例4: OnLoaded

        private async void OnLoaded(object sender, RoutedEventArgs e)
        {
            _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
            _generator = CompositionGeneratorFactory.GetCompositionGenerator(_compositor);

            var distance = 4f;
            var visualSize = new Vector2(225, 150);
            var vRefHeight = visualSize.Y + (visualSize.Y * 0.7f) + distance;
            var hRefWidth = visualSize.X + (visualSize.X * 0.7f) + distance;

            var vRefLeft = (float)(CompositionGrid1.ActualWidth - visualSize.X) / 2f;
            var vRefTop = (float)(CompositionGrid1.ActualHeight - vRefHeight) / 2f;
            var hRefLeft = (float)(CompositionGrid1.ActualWidth - hRefWidth) / 2f;
            var hRefTop = (float)(CompositionGrid1.ActualHeight - visualSize.Y) / 2f;

            var surfaceImage = await _generator.CreateImageSurfaceAsync(new Uri("ms-appx:///Assets/Images/Car.jpg"),
                visualSize.ToSize(), ImageSurfaceOptions.Default);
            var surfaceBrush = _compositor.CreateSurfaceBrush(surfaceImage.Surface);

            var visual1 = _compositor.CreateSpriteVisual();
            visual1.Size = visualSize;
            visual1.Offset = new Vector3(vRefLeft, vRefTop, 0);
            visual1.Brush = surfaceBrush;

            _generator.CreateReflection(visual1, distance);

            ElementCompositionPreview.SetElementChildVisual(CompositionGrid1, visual1);

            var invertEffect = new InvertEffect()
            {
                Source = new CompositionEffectSourceParameter("source")
            };

            var invertEffectFactory = _compositor.CreateEffectFactory(invertEffect);
            var invertBrush = invertEffectFactory.CreateBrush();
            invertBrush.SetSourceParameter("source", surfaceBrush);

            var visual2 = _compositor.CreateSpriteVisual();
            visual2.Size = visualSize;
            visual2.Offset = new Vector3(hRefLeft, hRefTop, 0);
            visual2.Brush = invertBrush;

            _generator.CreateReflection(visual2, distance, 0.7f, ReflectionLocation.Right);

            ElementCompositionPreview.SetElementChildVisual(CompositionGrid2, visual2);

            var visual3 = _compositor.CreateSpriteVisual();
            visual3.Size = visualSize;
            visual3.Offset = new Vector3(vRefLeft, vRefTop, 0);
            visual3.Brush = surfaceBrush;

            var inVisual = _compositor.CreateSpriteVisual();
            inVisual.Size = new Vector2(80, 80);
            inVisual.Offset = new Vector3(20, 10, 0);
            inVisual.Brush = _compositor.CreateColorBrush(Colors.Yellow);

            var inVisual2 = _compositor.CreateSpriteVisual();
            inVisual2.Size = new Vector2(80, 80);
            inVisual2.Offset = new Vector3(60, 60, 0);
            inVisual2.Brush = _compositor.CreateColorBrush(Colors.Blue);
            visual3.Children.InsertAtTop(inVisual2);
            visual3.Children.InsertAtTop(inVisual);

            _generator.CreateReflection(visual3, distance, 0.7f, ReflectionLocation.Bottom);

            ElementCompositionPreview.SetElementChildVisual(CompositionGrid3, visual3);

            var visual4 = _compositor.CreateSpriteVisual();
            visual4.Size = visualSize;
            visual4.Offset = new Vector3(hRefLeft, hRefTop, 0);
            visual4.Brush = surfaceBrush;

            var inVisual3 = _compositor.CreateSpriteVisual();
            inVisual3.Size = new Vector2(80, 80);
            inVisual3.Offset = new Vector3(20, 10, 0);
            inVisual3.Brush = _compositor.CreateColorBrush(Colors.Yellow);

            var inVisual4 = _compositor.CreateSpriteVisual();
            inVisual4.Size = new Vector2(80, 80);
            inVisual4.Offset = new Vector3(60, 40, 0);
            inVisual4.Brush = _compositor.CreateColorBrush(Colors.Blue);
            visual4.Children.InsertAtTop(inVisual3);
            visual4.Children.InsertAtTop(inVisual4);


            _generator.CreateReflection(visual4, distance, 0.7f, ReflectionLocation.Right);

            ElementCompositionPreview.SetElementChildVisual(CompositionGrid4, visual4);

        }
开发者ID:RareNCool,项目名称:CompositionProToolkit,代码行数:90,代码来源:VisualReflectionPage.xaml.cs

示例5: DrawingSurfaceRenderer

        public DrawingSurfaceRenderer(Compositor compositor, CompositionGraphicsDevice compositionGraphicsDevice)
        {
            drawingSurfaceVisual = compositor.CreateSpriteVisual();
            drawingSurface = compositionGraphicsDevice.CreateDrawingSurface(new Size(256, 256), DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied);
            drawingSurfaceVisual.Brush = compositor.CreateSurfaceBrush(drawingSurface);
            DrawDrawingSurface();

            compositionGraphicsDevice.RenderingDeviceReplaced += CompositionGraphicsDevice_RenderingDeviceReplaced;
        }
开发者ID:fengweijp,项目名称:Win2D,代码行数:9,代码来源:DrawingSurfaceRenderer.cs

示例6: LayoutRoot_Loaded

        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);
        }
开发者ID:JustinXinLiu,项目名称:EffectsAndAnimationsWinComposition,代码行数:46,代码来源:MainPage.xaml.cs

示例7: SamplePage_Loaded

        private void SamplePage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            // Get backing visual from shadow container and interop compositor
            _shadowContainer = ElementCompositionPreview.GetElementVisual(ShadowContainer);
            _compositor = _shadowContainer.Compositor;

            // Get CompositionImage, its sprite visual
            _image = VisualTreeHelperExtensions.GetFirstDescendantOfType<CompositionImage>(ShadowContainer);
            _imageVisual = _image.SpriteVisual;
           
            // Add drop shadow to image visual
            _shadow = _compositor.CreateDropShadow();
            _imageVisual.Shadow = _shadow;

            // Initialize sliders to shadow defaults - with the exception of offset
            BlurRadiusSlider.Value  = _shadow.BlurRadius;   //defaults to 9.0f
            OffsetXSlider.Value     = _shadow.Offset.X;     //defaults to 0
            OffsetYSlider.Value     = _shadow.Offset.Y;     //defaults to 0
            RedSlider.Value         = _shadow.Color.R;      //defaults to 0 (black.R)
            GreenSlider.Value       = _shadow.Color.G;      //defaults to 0 (black.G) 
            BlueSlider.Value        = _shadow.Color.B;      //defaults to 0 (black.B) 

            // Load mask asset onto surface using helpers in SamplesCommon
            _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor);
            _imageMaskSurface = _imageLoader.CreateManagedSurfaceFromUri(new Uri("ms-appx:///Assets/CircleMask.png"));

            // Create surface brush for mask
            CompositionSurfaceBrush mask = _compositor.CreateSurfaceBrush();
            mask.Surface = _imageMaskSurface.Surface;
            
            // Get surface brush from composition image
            CompositionSurfaceBrush source = _image.SurfaceBrush as CompositionSurfaceBrush;

            // Create mask brush for toggle mask functionality
            _maskBrush = _compositor.CreateMaskBrush();
            _maskBrush.Mask = mask;
            _maskBrush.Source = source;

            // Initialize toggle mask and animation to false
            _isMaskEnabled = false;
            _isAnimationEnabled = false;
          
        }
开发者ID:flying19880517,项目名称:composition,代码行数:43,代码来源:ShadowPlayground.xaml.cs

示例8: CompositionImage

        public CompositionImage()
        {
            this.DefaultStyleKey = typeof(CompositionImage);
            this.Background = new SolidColorBrush(Colors.Transparent);
            this._stretchMode = CompositionStretch.Uniform;
            this.Loading += CompImage_Loading;
            this.Unloaded += CompImage_Unloaded;
            this.SizeChanged += CompImage_SizeChanged;

            _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;

            // Intialize the statics as needed
            if (!_staticsInitialized)
            {
                _defaultPlaceholderBrush = _compositor.CreateColorBrush(Colors.DarkGray);

                TimeSpan duration = TimeSpan.FromMilliseconds(1000);
                _fadeOutAnimation = _compositor.CreateScalarKeyFrameAnimation();
                _fadeOutAnimation.InsertKeyFrame(0, 1);
                _fadeOutAnimation.InsertKeyFrame(1, 0);
                _fadeOutAnimation.Duration = duration;

                _scaleAnimation = _compositor.CreateVector2KeyFrameAnimation();
                _scaleAnimation.InsertKeyFrame(0, new Vector2(1.25f, 1.25f));
                _scaleAnimation.InsertKeyFrame(1, new Vector2(1, 1));
                _scaleAnimation.Duration = duration;

                _staticsInitialized = true;
            }

            // Initialize the surface loader if needed
            if (!SurfaceLoader.IsInitialized)
            {
                SurfaceLoader.Initialize(ElementCompositionPreview.GetElementVisual(this).Compositor);
            }

            _placeholderDelay = TimeSpan.FromMilliseconds(50);
            _surfaceBrush = _compositor.CreateSurfaceBrush(null);
        }
开发者ID:liquidboy,项目名称:X,代码行数:39,代码来源:CompositionImage.cs

示例9: InitializeComposition

        /// <summary>
        /// Initialize Composition
        /// </summary>
        private void InitializeComposition()
        {

            // Retrieve an instance of the Compositor from the backing Visual of the Page
            _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;

            // Create a root visual from the Compositor
            _root = _compositor.CreateContainerVisual();

            // Set the root ContainerVisual as the XAML Page Visual           
            ElementCompositionPreview.SetElementChildVisual(this, _root);

            // Assign initial values to variables used to store updated offsets for the visuals          
            float posXUpdated = _posX;
            float posYUpdated = _posY;


            //Create a list of image brushes that can be applied to a visual
            string[] imageNames = { "60Banana.png", "60Lemon.png", "60Vanilla.png", "60Mint.png", "60Orange.png", "110Strawberry.png", "60SprinklesRainbow.png" };
            _imageBrushList = new List<CompositionSurfaceBrush>();
            _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor);
            for (int k = 0; k < imageNames.Length; k++)
            {
                var surface = _imageLoader.LoadImageFromUri(new Uri("ms-appx:///Samples/SDK 14393/ImplicitAnimationTransformer/" + imageNames[k]));
                _imageBrushList.Add(_compositor.CreateSurfaceBrush(surface));
            }

            // Create nxn matrix of visuals where n=row/ColumnCount-1 and passes random image brush to the function
            // that creates a visual
            for (int i = 1; i < _rowCount; i++)
            {
                posXUpdated = i * _distance;
                for (int j = 1; j < _columnCount; j++)
                {
                    CompositionSurfaceBrush brush = _imageBrushList[randomBrush.Next(_imageBrushList.Count)];

                    posYUpdated = j * _distance;
                    _root.Children.InsertAtTop(CreateChildElement(brush, posXUpdated, posYUpdated));
                }
            }

            // Update the default animation state
            UpdateAnimationState(EnableAnimations.IsChecked == true);
        }
开发者ID:clarkezone,项目名称:composition,代码行数:47,代码来源:ImplicitAnimationTransformer.xaml.cs

示例10: LoadImageAsync

 private async void LoadImageAsync(Compositor compositor)
 {
     var surface = await SurfaceLoader.LoadFromUri(imageUri);
     visual.Brush = compositor.CreateSurfaceBrush(surface);
 }
开发者ID:chenjianwp,项目名称:WindowsUIDevLabs,代码行数:5,代码来源:LayerDepth.xaml.cs

示例11: OnLoaded

        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
            _generator = CompositionGeneratorFactory.GetCompositionGenerator(_compositor);

            _width = 300f;
            _height = 300f;
            // Create the combined geometry
            var ellipse1 = CanvasGeometry.CreateEllipse(_generator.Device, _width / 2, _height / 2, 0.45f * _width, 0.225f * _height);
            var ellipse2 = CanvasGeometry.CreateEllipse(_generator.Device, _width / 2, _height / 2, 0.225f * _width, 0.45f * _height);
            _combinedGeometry = ellipse1.CombineWith(ellipse2, Matrix3x2.Identity, CanvasGeometryCombine.Union);

            // Create custom shaped visual using CompositionMaskBrush
            _visual1 = _compositor.CreateSpriteVisual();
            _visual1.Size = new Vector2(_width, _height);
            _visual1.Offset = new Vector3(((CompositionGrid1.ActualWidth - _width) / 2).Single(),
                                         ((CompositionGrid1.ActualHeight - _height) / 2).Single(), 0);

            var visualChild = _compositor.CreateSpriteVisual();
            visualChild.Size = new Vector2(_width * 0.75f, _height * 0.75f);
            visualChild.Offset = new Vector3(_width*0.125f, _height*0.125f, 0);

            _visual1.Children.InsertAtTop(visualChild);

            // Create the CompositionMask
            var compositionMask = _generator.CreateMaskSurface(_visual1.Size.ToSize(), _combinedGeometry);
            // Create SurfaceBrush from CompositionMask
            var mask = _compositor.CreateSurfaceBrush(compositionMask.Surface);
            var source = _compositor.CreateColorBrush(Color.FromArgb(255, 0, 173, 239));
            // Create mask brush
            var maskBrush = _compositor.CreateMaskBrush();
            maskBrush.Mask = mask;
            maskBrush.Source = source;
            _visual1.Brush = maskBrush;

            ElementCompositionPreview.SetElementChildVisual(CompositionGrid1, _visual1);

            // Create custom shaped visual using CompositionMaskBrush
            _visual2 = _compositor.CreateSpriteVisual();
            _visual2.Size = new Vector2(_width, _height);
            _visual2.Offset = new Vector3(((CompositionGrid2.ActualWidth - _width) / 2).Single(),
                                         ((CompositionGrid2.ActualHeight - _height) / 2).Single(), 0);

            // Create the CompositionMask filled with color
            var compositionMask2 =
                _generator.CreateGeometrySurface(_visual2.Size.ToSize(), _combinedGeometry, Color.FromArgb(192, 192, 0, 0));
            // Create SurfaceBrush from CompositionMask
            var surfaceBrush = _compositor.CreateSurfaceBrush(compositionMask2.Surface);
            _visual2.Brush = surfaceBrush;

            ElementCompositionPreview.SetElementChildVisual(CompositionGrid2, _visual2);

            // Initialize the visuals for the Animated Canvas
            // Create the container to host the visuals
            var container = _compositor.CreateContainerVisual();
            container.Size = new Vector2(CompositionGrid3.ActualWidth.Single(), CompositionGrid3.ActualHeight.Single());

            // Background Visual
            _bgVisual = _compositor.CreateSpriteVisual();
            _bgVisual.Size = new Vector2(_width, _height);
            _bgVisual.Offset = new Vector3(((CompositionGrid3.ActualWidth - _width) / 2).Single(),
                                         ((CompositionGrid3.ActualHeight - _height) / 2).Single(), 0);

            var radians = ((45f*Math.PI)/180).Single();
            var bgGeometry = _combinedGeometry.Transform(Matrix3x2.CreateRotation(radians, new Vector2(_width/2, _height/2)));
            var bgMask = _generator.CreateGeometrySurface(_bgVisual.Size.ToSize(), bgGeometry, Color.FromArgb(255, 0, 173, 239));
            var bgBrush = _compositor.CreateSurfaceBrush(bgMask.Surface);
            _bgVisual.Brush = bgBrush;

            container.Children.InsertAtBottom(_bgVisual);

            // Animated Visual
            _animatedVisual = _compositor.CreateSpriteVisual();
            _animatedVisual.Size = new Vector2(_width, _height);
            _animatedVisual.Offset = new Vector3(((CompositionGrid3.ActualWidth - _width) / 2).Single(),
                                                ((CompositionGrid3.ActualHeight - _height) / 2).Single(), 0);
            // Create the Excluded geometry
            _outerGeometry = CanvasGeometry.CreateRectangle(_generator.Device, 0, 0, _width, _height);
            var excludedGeometry = _outerGeometry.CombineWith(_combinedGeometry, Matrix3x2.Identity, CanvasGeometryCombine.Exclude);
            // Create the CompositionMask
            _animatedMaskSurface = _generator.CreateGeometrySurface(_animatedVisual.Size.ToSize(), excludedGeometry, Color.FromArgb(192, 192, 0, 0));
            var animBrush = _compositor.CreateSurfaceBrush(_animatedMaskSurface.Surface);
            _animatedVisual.Brush = animBrush;

            container.Children.InsertAtTop(_animatedVisual);

            ElementCompositionPreview.SetElementChildVisual(CompositionGrid3, container);
        }
开发者ID:RareNCool,项目名称:CompositionProToolkit,代码行数:88,代码来源:MaskSurfacePage.xaml.cs

示例12: InitializeCompositionVariables

        //private async Task HideStatusBar()
        //{
        //    //if (ApiInformation.IsApiContractPresent("Windows.Phone.PhoneContract", 1, 0))
        //    //{
        //    //    var statusBar = StatusBar.GetForCurrentView();
        //    //    await statusBar.HideAsync();
        //    //}
        //}

        private void InitializeCompositionVariables()
        {
            var bounds = ApplicationView.GetForCurrentView().VisibleBounds;
            var maxWindowWidth = bounds.Width.ToFloat();
            var maxWindowHeight = bounds.Height.ToFloat();
            var maxWindowRadius = Math.Max(maxWindowWidth, maxWindowHeight);

            // Setup sky visual's size, position, opacity, etc.
            _skyVisual = Sky.ContainerVisual();
            _skyVisual.Size = new Vector2(maxWindowRadius * SkyVisualAreaRatio);
            _skyVisual.Offset = new Vector3(-SkyVisualRadius + maxWindowWidth / 2.0f, -SkyVisualRadius + maxWindowHeight / 2.0f, 0.0f);
            _skyVisual.CenterPoint = new Vector3(SkyVisualRadius, SkyVisualRadius, 0.0f);
            _skyVisual.Opacity = 0;

            _compositor = _skyVisual.Compositor;
            _reading = _compositor.CreatePropertySet();
            _reading.InsertVector3("Offset", new Vector3(0.0f, 0.0f, 0.0f));
            _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor);
            _circleBrush = _compositor.CreateSurfaceBrush();
            _circleBrush.Surface = _imageLoader.LoadImageFromUri(new Uri(StarUriString));

            if (_inclinometer != null) SetupSkyVisualOffsetExpressionAnimation();
        }
开发者ID:JustinXinLiu,项目名称:Continuity,代码行数:32,代码来源:StarsBackground.xaml.cs

示例13: InitComposition

        /// <summary>
        /// Initializes the Composition elements
        /// </summary>
        private void InitComposition()
        {
            // Compositor
            _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
            // CompositionGenerator
            _generator = CompositionGeneratorFactory.GetCompositionGenerator(_compositor);
            
            // Fade Out Animation
            _fadeOutAnimation = _compositor.CreateScalarKeyFrameAnimation();
            _fadeOutAnimation.InsertKeyFrame(1f, 0);
            _fadeOutAnimation.Duration = TransitionDuration;
            // Fade In Animation
            _fadeInAnimation = _compositor.CreateScalarKeyFrameAnimation();
            _fadeInAnimation.InsertKeyFrame(1f, 1);
            _fadeInAnimation.Duration = TransitionDuration;
            // Color Animation
            _colorAnimation = _compositor.CreateColorKeyFrameAnimation();
            _colorAnimation.Duration = TransitionDuration;
            // Offset Animation
            _offsetAnimation = _compositor.CreateVector3KeyFrameAnimation();
            _offsetAnimation.Target = "Offset";
            _offsetAnimation.Duration = TransitionDuration;
            _offsetAnimation.InsertKeyFrame(1f, Vector3.Zero);
            // Alignment animations
            _alignXAnimation = _compositor.CreateScalarKeyFrameAnimation();
            _alignXAnimation.Duration = AlignmentTransitionDuration;
            _alignYAnimation = _compositor.CreateScalarKeyFrameAnimation();
            _alignYAnimation.Duration = AlignmentTransitionDuration;

            // ZoomIn Animation Group
            _scaleAnimation = _compositor.CreateVector3KeyFrameAnimation();
            _scaleAnimation.Target = "Scale";
            _scaleAnimation.InsertKeyFrame(1f, Vector3.One);
            _scaleAnimation.Duration = TransitionDuration;
            _zoomInAnimationGroup = _compositor.CreateAnimationGroup();
            _zoomInAnimationGroup.Add(_scaleAnimation);
            _zoomInAnimationGroup.Add(_offsetAnimation);

            // Visuals
            _rootContainer = _compositor.CreateContainerVisual();
            _frameLayer = _compositor.CreateLayerVisual();
            _frameBackgroundVisual = _compositor.CreateSpriteVisual();
            _frameContentVisual = _compositor.CreateSpriteVisual();
            _placeholderContentVisual = _compositor.CreateSpriteVisual();
            _placeholderBackgroundVisual = _compositor.CreateSpriteVisual();
            _nextVisualContent = _compositor.CreateSpriteVisual();

            _frameLayer.Children.InsertAtTop(_frameBackgroundVisual);
            _frameLayer.Children.InsertAtTop(_frameContentVisual);
            _frameLayer.Children.InsertAtTop(_placeholderBackgroundVisual);
            _frameLayer.Children.InsertAtTop(_placeholderContentVisual);
            _frameLayer.Children.InsertAtTop(_nextVisualContent);

            // Placeholder content
            _placeholderContentMask = _generator.CreateGeometrySurface(PlaceholderSize, GetPlaceHolderGeometry(),
                PlaceholderColor, PlaceholderBackground);
            _placeholderContentBrush = _compositor.CreateSurfaceBrush(_placeholderContentMask.Surface);
            _placeholderContentVisual.Brush = _placeholderContentBrush;
            // Placeholder background
            _placeholderBackgroundVisual.Brush = _compositor.CreateColorBrush(PlaceholderBackground);

            // By default placeholder visual will not be visible
            HidePlaceholder();

            // Shadow visual
            _shadowVisual = _compositor.CreateSpriteVisual();

            _rootContainer.Children.InsertAtBottom(_shadowVisual);
            _rootContainer.Children.InsertAtTop(_frameLayer);

            _frameBackgroundVisual.Brush = _compositor.CreateColorBrush(FrameBackground);

            // Create the effect to create the opacity mask
            var layerEffect = new CompositeEffect
            {
                // CanvasComposite.DestinationIn - Intersection of source and mask. 
                // Equation: O = MA * S
                // where O - Output pixel, MA - Mask Alpha, S - Source pixel.
                Mode = CanvasComposite.DestinationIn,
                Sources =
                        {
                            new CompositionEffectSourceParameter("source"),
                            new CompositionEffectSourceParameter("mask")
                        }
            };

            var layerEffectFactory = _compositor.CreateEffectFactory(layerEffect);
            _layerEffectBrush = layerEffectFactory.CreateBrush();

            // The mask for the imageFrame
            _frameLayerMask = _generator.CreateMaskSurface(new Size(0, 0), null);
            _layerEffectBrush.SetSourceParameter("mask", _compositor.CreateSurfaceBrush(_frameLayerMask.Surface));
            // Apply the mask effect to the frameLayer
            _frameLayer.Effect = _layerEffectBrush;

            ElementCompositionPreview.SetElementChildVisual(this, _rootContainer);
        }
开发者ID:RareNCool,项目名称:CompositionProToolkit,代码行数:100,代码来源:ImageFrame.cs


注:本文中的Compositor.CreateSurfaceBrush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。