本文整理汇总了C#中Compositor.CreateEffectFactory方法的典型用法代码示例。如果您正苦于以下问题:C# Compositor.CreateEffectFactory方法的具体用法?C# Compositor.CreateEffectFactory怎么用?C# Compositor.CreateEffectFactory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Compositor
的用法示例。
在下文中一共展示了Compositor.CreateEffectFactory方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: Initialize
public static void Initialize(Compositor compositor)
{
s_random = new Random();
s_compositor = compositor;
// Create a animatable desaturation effect description
var effectDesc = new SaturationEffect();
effectDesc.Name = "myEffect";
effectDesc.Source = new CompositionEffectSourceParameter("Image");
s_saturationEffectFactory = compositor.CreateEffectFactory(
effectDesc,
new string[] { "myEffect.Saturation" });
}
示例3: 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);
}
示例4: ImagePopupViewer
/// <summary>
/// Private constructor as Show() is responsible for creating an instance
/// </summary>
private ImagePopupViewer(Func<object, bool, Uri> photoGetter, string initialPhoto)
{
this.InitializeComponent();
_imageUriGetterFunc = photoGetter;
_transition = new ConnectedTransition();
_compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
this.Loaded += ImagePopupViewer_Loaded;
this.Unloaded += ImagePopupViewer_Unloaded;
// Bring the selected item into view
_initialPhoto = initialPhoto;
// Hide until the content is available
this.Opacity = 0;
BackgroundImage.ImageOpened += BackgroundImage_FirstOpened;
// Disable the placeholder as we'll be using a transition
PrimaryImage.PlaceholderDelay = TimeSpan.FromMilliseconds(-1);
BackgroundImage.PlaceholderDelay = TimeSpan.FromMilliseconds(-1);
BackgroundImage.LoadTimeEffectHandler = SampleImageColor;
BackgroundImage.SharedSurface = true;
// Create a crossfade brush to animate image transitions
IGraphicsEffect graphicsEffect = new ArithmeticCompositeEffect()
{
Name = "CrossFade",
Source1Amount = 0,
Source2Amount = 1,
MultiplyAmount = 0,
Source1 = new CompositionEffectSourceParameter("ImageSource"),
Source2 = new CompositionEffectSourceParameter("ImageSource2"),
};
CompositionEffectFactory factory = _compositor.CreateEffectFactory(graphicsEffect, new[] { "CrossFade.Source1Amount", "CrossFade.Source2Amount" });
_crossFadeBrush = factory.CreateBrush();
}
示例5: LayoutRoot_Loaded
async 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;
// load the background image
var image = _compositor.DefaultGraphicsDevice.CreateImageFromUri(new Uri("ms-appx:///Assets/White.png"));
await image.CompleteLoadAsync();
// todo: not sure why GaussianBlurEffect doesn't work??
// Got a feeling it might have something to do with the Source setting,
// maybe it's just not supported yet?
var effectDefination = new SaturationEffect // new GaussianBlurEffect
{
//BorderMode = EffectBorderMode.Soft,
//BlurAmount = 5f,
//Optimization = EffectOptimization.Quality,
Source = new CompositionEffectSourceParameter("Overlay")
};
// create the actual effect
var effectFactory = _compositor.CreateEffectFactory(effectDefination);
var effect = effectFactory.CreateEffect();
effect.SetSourceParameter("Overlay", image);
// create the effect visual
_effectVisual = _compositor.CreateEffectVisual();
_effectVisual.Effect = effect;
_effectVisual.Opacity = 0.8f;
_effectVisual.Size = new Vector2((float)this.ImagePanel.ActualWidth, (float)this.ImagePanel.ActualHeight);
// place the effect visual onto the UI
imagePanelVisual.Children.InsertAtTop(_effectVisual);
}
示例6: 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);
}
示例7: 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);
}
示例8: 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);
}