本文整理汇总了C#中Compositor.CreateMaskBrush方法的典型用法代码示例。如果您正苦于以下问题:C# Compositor.CreateMaskBrush方法的具体用法?C# Compositor.CreateMaskBrush怎么用?C# Compositor.CreateMaskBrush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Compositor
的用法示例。
在下文中一共展示了Compositor.CreateMaskBrush方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例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;
// 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;
}
示例3: 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);
}