本文整理汇总了C#中Compositor.CreateSpriteVisual方法的典型用法代码示例。如果您正苦于以下问题:C# Compositor.CreateSpriteVisual方法的具体用法?C# Compositor.CreateSpriteVisual怎么用?C# Compositor.CreateSpriteVisual使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Compositor
的用法示例。
在下文中一共展示了Compositor.CreateSpriteVisual方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例2: SetupVisuals
public void SetupVisuals()
{
// Intialize the Compositor
_compositor = new Compositor();
_root = ElementCompositionPreview.GetElementVisual(Container);
_compositor = _root.Compositor;
// Create the Blue Square
var blueSquareVisual = _compositor.CreateSpriteVisual();
blueSquareVisual.Brush = _compositor.CreateColorBrush(Colors.Blue);
blueSquareVisual.Size = new System.Numerics.Vector2(50.0f, 50.0f);
blueSquareVisual.Offset = new Vector3(100.00f, 50.00f, 0.00f);
// Create the Green Square with 20% opacity
var greenSquareVisual = _compositor.CreateSpriteVisual();
greenSquareVisual.Brush = _compositor.CreateColorBrush(Colors.Green);
greenSquareVisual.Size = new System.Numerics.Vector2(50.0f, 50.0f);
greenSquareVisual.Offset = new Vector3(150.00f, 100.00f, 0.00f);
greenSquareVisual.Opacity = 0.20f;
// Add the Visuals to the tree
ContainerVisual mainContainer = _compositor.CreateContainerVisual();
ElementCompositionPreview.SetElementChildVisual(Container, mainContainer);
mainContainer.Children.InsertAtTop(blueSquareVisual);
mainContainer.Children.InsertAtTop(greenSquareVisual);
_source = greenSquareVisual;
_target = blueSquareVisual;
}
示例3: Parallax_Expression
public void Parallax_Expression()
{
_compositor = new Compositor();
_root = ElementCompositionPreview.GetElementVisual(Container);
_compositor = _root.Compositor;
// Create the Blue Square
var blueSquareVisual = _compositor.CreateSpriteVisual();
blueSquareVisual.Brush = _compositor.CreateColorBrush(Colors.Blue);
blueSquareVisual.Size = new System.Numerics.Vector2(100.0f, 100.0f);
blueSquareVisual.Offset = new Vector3(100.00f, 50.00f, 0.00f);
// Create the Green Square
var greenSquareVisual = _compositor.CreateSpriteVisual();
greenSquareVisual.Brush = _compositor.CreateColorBrush(Colors.Green);
greenSquareVisual.Size = new System.Numerics.Vector2(50.0f, 50.0f);
greenSquareVisual.Offset = new Vector3(100.00f, 50.00f, 0.00f);
// Add the Blue and Green square visuals to the tree
ContainerVisual mainContainer = _compositor.CreateContainerVisual();
ElementCompositionPreview.SetElementChildVisual(Container, mainContainer);
mainContainer.Children.InsertAtTop(blueSquareVisual);
mainContainer.Children.InsertAtTop(greenSquareVisual);
_foreground = greenSquareVisual;
_background = blueSquareVisual;
}
示例4: SamplePage_Loaded
private void SamplePage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
// Acquire Compositor and set up basic visual tree structure
_xamlRoot = ElementCompositionPreview.GetElementVisual(MainGrid);
_compositor = _xamlRoot.Compositor;
_root = _compositor.CreateContainerVisual();
_mainImage = Image.SpriteVisual;
ElementCompositionPreview.SetElementChildVisual(ImageContainer, _root);
_root.Children.InsertAtTop(_mainImage);
// Add visual indicators to show the position of AnchorPoint and CenterPoint
_indicatorContainer = _compositor.CreateContainerVisual();
_apIndicator = _compositor.CreateSpriteVisual();
_apIndicator.Size = new Vector2(10, 10);
_apIndicator.AnchorPoint = new Vector2(0.5f, 0.5f);
_apIndicator.Brush = _compositor.CreateColorBrush(Windows.UI.Colors.Red);
_cpIndicator = _compositor.CreateSpriteVisual();
_cpIndicator.Size = new Vector2(10, 10);
_cpIndicator.AnchorPoint = new Vector2(0.5f, 0.5f);
_cpIndicator.Brush = _compositor.CreateColorBrush(Windows.UI.Colors.Green);
_root.Children.InsertAtTop(_indicatorContainer);
_indicatorContainer.Children.InsertAtTop(_cpIndicator);
_indicatorContainer.Children.InsertAtTop(_apIndicator);
// Specify a clip to prevent image from overflowing into the sliders list
Visual containerGrid = ElementCompositionPreview.GetElementVisual(ContentGrid);
containerGrid.Size = new Vector2((float)ContentGrid.ActualWidth, (float)ContentGrid.ActualHeight);
ContentGrid.SizeChanged += (s, a) =>
{
containerGrid.Size = new Vector2((float)ContentGrid.ActualWidth, (float)ContentGrid.ActualHeight);
};
containerGrid.Clip = _compositor.CreateInsetClip();
// Create list of properties to add as sliders
var list = new List<TransformPropertyModel>();
list.Add(new TransformPropertyModel(AnchorPointXAction) { PropertyName = "AnchorPoint - X (Red)", MinValue = -1, MaxValue = 2, StepFrequency = 0.01f, Value = _mainImage.AnchorPoint.X });
list.Add(new TransformPropertyModel(AnchorPointYAction) { PropertyName = "AnchorPoint - Y (Red)", MinValue = -1, MaxValue = 2, StepFrequency = 0.01f, Value = _mainImage.AnchorPoint.Y });
list.Add(new TransformPropertyModel(CenterPointXAction) { PropertyName = "CenterPoint - X (Green)", MinValue = -600, MaxValue = 600, StepFrequency = 1f, Value = _mainImage.CenterPoint.X });
list.Add(new TransformPropertyModel(CenterPointYAction) { PropertyName = "CenterPoint - Y (Green)", MinValue = -600, MaxValue = 600, StepFrequency = 1f, Value = _mainImage.CenterPoint.Y });
list.Add(new TransformPropertyModel(RotationAction) { PropertyName = "Rotation (in Degrees)", MinValue = 0, MaxValue = 360, StepFrequency = 1f, Value = _mainImage.RotationAngleInDegrees });
list.Add(new TransformPropertyModel(ScaleXAction) { PropertyName = "Scale - X", MinValue = 0, MaxValue = 3, StepFrequency = 0.01f, Value = _mainImage.Scale.X });
list.Add(new TransformPropertyModel(ScaleYAction) { PropertyName = "Scale - Y", MinValue = 0, MaxValue = 3, StepFrequency = 0.01f, Value = _mainImage.Scale.Y });
list.Add(new TransformPropertyModel(OffsetXAction) { PropertyName = "Offset - X", MinValue = -200, MaxValue = 200, StepFrequency = 1f, Value = _mainImage.Offset.X });
list.Add(new TransformPropertyModel(OffsetYAction) { PropertyName = "Offset - Y", MinValue = -200, MaxValue = 200, StepFrequency = 1f, Value = _mainImage.Offset.Y });
XamlItemsControl.ItemsSource = list;
}
示例5: SetupVisual
// Define and setup the Green Square Visual that will be animated
public void SetupVisual()
{
// Intialize the Compositor
_compositor = new Compositor();
_root = (ContainerVisual)ElementCompositionPreview.GetElementVisual(Container);
_compositor = _root.Compositor;
_linear = _compositor.CreateLinearEasingFunction();
// Create Green Square
var colorVisual = _compositor.CreateSpriteVisual();
colorVisual.Brush = _compositor.CreateColorBrush(Colors.Green);
colorVisual.Size = new Vector2(150.0f, 150.0f);
colorVisual.Offset = new Vector3(250.0f, 50.0f, 0.0f);
colorVisual.CenterPoint = new Vector3(75.0f, 75.0f, 0.0f);
_target = colorVisual;
// Create Blue Square
var colorVisual2 = _compositor.CreateSpriteVisual();
colorVisual2.Brush = _compositor.CreateColorBrush(Colors.Aqua);
colorVisual2.Size = new Vector2(200.0f, 150.0f);
colorVisual2.Offset = new Vector3(25.0f, 50.0f, 0.0f);
colorVisual2.IsVisible = false;
_target2 = colorVisual2;
// Add the Blue and Green square visuals to the tree
_mainContainer = _compositor.CreateContainerVisual();
ElementCompositionPreview.SetElementChildVisual(Container, _mainContainer);
_mainContainer.Children.InsertAtTop(_target);
_mainContainer.Children.InsertAtTop(_target2);
// Create Scoped batch for animations
_batch = _compositor.CreateScopedBatch(CompositionBatchTypes.Animation);
// Add Animation1 to the batch
Animation1(_target);
// Suspend the batch to exclude an animation
_batch.Suspend();
// Exluding Animation2 from batch
Animation2(_target);
// Resuming the batch to collect additional animations
_batch.Resume();
// Add Animation3 to the batch
Animation3(_target);
// Batch is ended an no objects can be added
_batch.End();
// Method triggered when batch completion event fires
_batch.Completed += OnBatchCompleted;
}
示例6: SetupDestinationEffect
public void SetupDestinationEffect(Compositor compositor)
{
// Create SpriteVisual for blur effect
_destVisual = compositor.CreateSpriteVisual();
_destVisual.Size = new Vector2(0, 0);
// Create graphics effect for blur
var graphicsEffect = new GaussianBlurEffect
{
Name = "GB",
Source = new CompositionEffectSourceParameter("destinationSource"),
BlurAmount = 10f,
BorderMode = EffectBorderMode.Hard,
Optimization = EffectOptimization.Balanced
};
var effectFactory = compositor.CreateEffectFactory(graphicsEffect);
var blurEffect = effectFactory.CreateBrush();
var destinationBrush = compositor.CreateBackdropBrush();
blurEffect.SetSourceParameter("destinationSource", destinationBrush);
// Set the SpriteVisual's brush as blur effect
_destVisual.Brush = blurEffect;
// Insert the destination visual as child of the BlurRect UIElement.
// Since the BlurRect is between the text of the flyout and the content of the page,
// the destination visual will blur the content of the page.
ElementCompositionPreview.SetElementChildVisual(BlurRect, _destVisual);
}
示例7: Page_Loaded
private void Page_Loaded(object sender, RoutedEventArgs e)
{
ThumbnailList.ItemsSource = Model.Items;
// Populate the Effect combobox
IList<ComboBoxItem> effectList = new List<ComboBoxItem>();
foreach (EffectTypes type in Enum.GetValues(typeof(EffectTypes)))
{
ComboBoxItem item = new ComboBoxItem();
item.Tag = type;
item.Content = type.ToString();
effectList.Add(item);
}
EffectSelection.ItemsSource = effectList;
EffectSelection.SelectedIndex = 0;
// Get the current compositor
_compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
// Create the destinatio sprite, sized to cover the entire list
_destinationSprite = _compositor.CreateSpriteVisual();
_destinationSprite.Size = new Vector2((float)ThumbnailList.ActualWidth, (float)ThumbnailList.ActualHeight);
// Start out with the destination layer invisible to avoid any cost until necessary
_destinationSprite.IsVisible = false;
ElementCompositionPreview.SetElementChildVisual(ThumbnailList, _destinationSprite);
// Update the effect to set the appropriate brush
UpdateEffect();
}
示例8: 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();
}
示例9: CompImage_Loading
private void CompImage_Loading(FrameworkElement sender, object args)
{
_compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
_sprite = _compositor.CreateSpriteVisual();
_sprite.Size = new Vector2((float)ActualWidth, (float)ActualHeight);
ElementCompositionPreview.SetElementChildVisual(this, _sprite);
}
示例10: 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;
}
示例11: 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);
}
示例12: Backdrop
public Backdrop()
{
DefaultStyleKey = typeof(Backdrop);
SizeChanged += (sender, e) =>
{
UpdateVisualSize();
};
var rootVisual = ElementCompositionPreview.GetElementVisual(this);
_compositor = rootVisual.Compositor;
_blurVisual = _compositor.CreateSpriteVisual();
var brush = CreateBlurBrush();
brush.SetSourceParameter("Source", _compositor.CreateBackdropBrush());
_blurVisual.Brush = brush;
ElementCompositionPreview.SetElementChildVisual(this, _blurVisual);
}
示例13: ShowVisual_Click
private void ShowVisual_Click(object sender, RoutedEventArgs e)
{
// Initialize the Compositor
_compositor = new Compositor();
_root = ElementCompositionPreview.GetElementVisual(root);
_compositor = _root.Compositor;
// Generate the Green Square
var colorVisual = _compositor.CreateSpriteVisual();
colorVisual.Brush = _compositor.CreateColorBrush(Colors.Green);
colorVisual.Size = new Vector2(150.0f, 150.0f);
colorVisual.Offset = new Vector3(50.0f, 50.0f, 0.0f);
// Add the image to the tree
ElementCompositionPreview.SetElementChildVisual(root, colorVisual);
_target = colorVisual;
}
示例14: SetupVisual
// Defines the Visual to be animated in this sample and adds it to the Visual Tree
public void SetupVisual()
{
// Intialize the Compositor
_compositor = new Compositor();
_root = ElementCompositionPreview.GetElementVisual(Container);
_compositor = _root.Compositor;
// Create the Blue Square
var colorVisual = _compositor.CreateSpriteVisual();
colorVisual.Brush = _compositor.CreateColorBrush(Colors.Blue);
colorVisual.Size = new System.Numerics.Vector2(150.0f, 150.0f);
colorVisual.Offset = new Vector3(100.00f, 50.00f, 0.00f);
// Add the Visual to the tree
ElementCompositionPreview.SetElementChildVisual(Container, colorVisual);
_target = colorVisual;
}
示例15: SetupBlur
private void SetupBlur()
{
compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
var blur = new GaussianBlurEffect
{
Name = "Blur",
Source = new CompositionEffectSourceParameter("Backdrop"),
BlurAmount = 0.0f,
BorderMode = EffectBorderMode.Hard
};
var blend = new BlendEffect
{
Name = "Blend",
Foreground = new ColorSourceEffect
{
Color = Color.FromArgb(128, 30, 30, 220),
Name = "ColorSource"
},
Background = blur,
Mode = BlendEffectMode.Overlay
};
var effectFactory = compositor.CreateEffectFactory(blend, new[] {"Blur.BlurAmount"});
brush = effectFactory.CreateBrush();
var backdrop = compositor.CreateBackdropBrush();
brush.SetSourceParameter("Backdrop", backdrop);
var sprite = compositor.CreateSpriteVisual();
sprite.Brush = brush;
sprite.Size = new Vector2((float) TargetImage.ActualWidth, (float) TargetImage.ActualHeight);
ElementCompositionPreview.SetElementChildVisual(TargetImage, sprite);
}