/// <inheritdoc cref="XamlCompositionBrushBase"/> protected override void OnConnected() { if (CompositionBrush == null) { // Effects setup SceneLightingEffect sceneLightingEffect = new SceneLightingEffect // Base lighting effect { Name = "Light", SpecularShine = (float)SpecularShine, SpecularAmount = (float)SpecularAmount, DiffuseAmount = (float)DiffuseAmount, AmbientAmount = 0 }; _LuminanceEffect = new LuminanceToAlphaEffect { Source = sceneLightingEffect }; // Map the bright areas of the light to an opacity mask _InverseEffect = new InvertEffect { Source = _LuminanceEffect }; // Invert the colors to make the brighter areas white _Factory = Window.Current.Compositor.CreateEffectFactory(_InverseEffect, new[] { "Light.DiffuseAmount", "Light.SpecularShine", "Light.SpecularAmount" }); // Create and store the brush _Brush = _Factory.CreateBrush(); CompositionBrush = _Brush; } base.OnConnected(); }
public BackDrop() { var myBackingVisual = ElementCompositionPreview.GetElementVisual(this as UIElement); m_compositor = myBackingVisual.Compositor; m_blurBrush = BuildColoredBlurMixerBrush(); m_blurBrush.SetSourceParameter("source", m_compositor.CreateBackdropBrush()); m_blurVisual = m_compositor.CreateSpriteVisual(); m_blurVisual.Brush = m_blurBrush; m_blurVisual.Properties.InsertScalar("BlurValue", 10.0f); m_blurVisual.Properties.InsertScalar("FadeValue", 1.0f); SetupPropertySetExpression(); m_container = m_compositor.CreateContainerVisual(); m_container.Children.InsertAtTop(m_blurVisual); //CreateDropshadow(); ElementCompositionPreview.SetElementChildVisual(this as UIElement, m_container); this.Loading += OnLoading; this.Unloaded += OnUnloaded; }
private void InitializeBlur() { _compositor = Window.Current.Compositor; ElementCompositionPreview.GetElementVisual(this).Clip = _compositor.CreateInsetClip(); var graphicsEffect = new GaussianBlurEffect { Name = "Blur", BlurAmount = 0, BorderMode = EffectBorderMode.Hard, Source = new CompositionEffectSourceParameter("backdrop") }; var effectFactory = _compositor.CreateEffectFactory(graphicsEffect, new[] { "Blur.BlurAmount" }); var effectBrush = effectFactory.CreateBrush(); var backdrop = _compositor.CreateBackdropBrush(); effectBrush.SetSourceParameter("backdrop", backdrop); _blurBrush = effectBrush; _blurVisual = _compositor.CreateSpriteVisual(); _blurVisual.Brush = _blurBrush; // Why does this crashes due to an access violation exception on certain devices? ElementCompositionPreview.SetElementChildVisual(BlurPanel, _blurVisual); }
private void Department_Loaded(object sender, RoutedEventArgs e) { effectVisual = compositor.CreateSpriteVisual(); var destinationBrush = compositor.CreateBackdropBrush(); //Create the Effect you want var graphicsEffect = new GaussianBlurEffect { Name = "Blur", BlurAmount = 0f, BorderMode = EffectBorderMode.Hard, Optimization = EffectOptimization.Balanced, Source = new CompositionEffectSourceParameter("Background") }; effectFactory = compositor.CreateEffectFactory(graphicsEffect, new[] { "Blur.BlurAmount" }); effectBrush = effectFactory.CreateBrush(); effectBrush.SetSourceParameter("Background", destinationBrush); effectVisual.Brush = effectBrush; effectVisual.Size = new System.Numerics.Vector2(900, 400); ElementCompositionPreview.SetElementChildVisual(CoverImage, effectVisual); //Create Spring Animation for nature increase and decrease value _springAnimation = compositor.CreateSpringScalarAnimation(); _springAnimation.Period = TimeSpan.FromSeconds(0.70); //_springAnimation.DampingRatio = 0.25f; }
public void Remove() { // Remove effect if (null != this._foregroundElement) { this._foregroundElement.Opacity = 1.0f; } if (null != this._blurVisual) { this._blurVisual.Brush = null; this._blurVisual?.StopAnimation("Size"); } this._bindSizeAnimation?.Dispose(); this._bindSizeAnimation = null; this._effectBrush?.Dispose(); this._effectBrush = null; this._backdropBrush?.Dispose(); this._backdropBrush = null; this._blurEffect?.Dispose(); this._blurEffect = null; // NOTE: No API to remove the child visual //this._blurVisual?.Dispose(); //this._blurVisual = null; }
private void Initialize() { _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; _frostEffect = new GaussianBlurEffect { Name = "Blur", BlurAmount = 0.0f, BorderMode = EffectBorderMode.Hard, Optimization = EffectOptimization.Balanced, Source = new CompositionEffectSourceParameter("backdropBrush") }; // Create an instance of the effect and set its source to a CompositionBackdropBrush _effectFactory = _compositor.CreateEffectFactory(_frostEffect); _backdropBrush = _compositor.CreateHostBackdropBrush(); _effectBrush = _effectFactory.CreateBrush(); // Create a Visual to contain the frosted glass effect _frostVisual = _compositor.CreateSpriteVisual(); _frostVisual.Brush = _effectBrush; _frostVisual.Size = new Vector2((float)ActualWidth, (float)ActualHeight); _effectBrush.SetSourceParameter("backdropBrush", _backdropBrush); // Add the blur as a child of the host in the visual tree ElementCompositionPreview.SetElementChildVisual(this, _frostVisual); }
/// <summary> /// Initializes new instance of the <see cref="BaseBackDrop"/> class. /// </summary> /// <param name="useHostBackdrop">Enables host backdrop is platform supports it.</param> public BaseBackDrop(bool useHostBackdrop = false) { m_rootVisual = ElementCompositionPreview.GetElementVisual(this as UIElement); Compositor = m_rootVisual.Compositor; m_blurVisual = Compositor.CreateSpriteVisual(); m_noiseBrush = Compositor.CreateSurfaceBrush(); CompositionEffectBrush brush = BuildBlurBrush(); if (useHostBackdrop && IsHostBackDropSupported) { brush.SetSourceParameter("source", m_compositor.CreateHostBackdropBrush()); } else { brush.SetSourceParameter("source", m_compositor.CreateBackdropBrush()); } m_blurBrush = brush; m_blurVisual.Brush = m_blurBrush; BlurAmount = 9; //TintColor = Colors.Transparent; ElementCompositionPreview.SetElementChildVisual(this as UIElement, m_blurVisual); this.Loading += OnLoading; this.Unloaded += OnUnloaded; }
public BackDrop() { m_rootVisual = ElementCompositionPreview.GetElementVisual(this as UIElement); Compositor = m_rootVisual.Compositor; m_blurVisual = Compositor.CreateSpriteVisual(); #if SDKVERSION_14393 m_noiseBrush = Compositor.CreateSurfaceBrush(); CompositionEffectBrush brush = BuildBlurBrush(); brush.SetSourceParameter("source", m_compositor.CreateBackdropBrush()); m_blurBrush = brush; m_blurVisual.Brush = m_blurBrush; BlurAmount = 9; TintColor = Colors.Transparent; #else m_blurBrush = Compositor.CreateColorBrush(Colors.White); m_blurVisual.Brush = m_blurBrush; #endif ElementCompositionPreview.SetElementChildVisual(this as UIElement, m_blurVisual); this.Loading += OnLoading; this.Unloaded += OnUnloaded; }
private void applyBlurBackDrop(Panel panel) { _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; _blurSprite = _compositor.CreateSpriteVisual(); _blurSprite.Size = new Vector2((float)panel.ActualWidth, (float)panel.ActualHeight); ElementCompositionPreview.SetElementChildVisual(panel, _blurSprite); // Create an effect description GaussianBlurEffect blurEffect = new GaussianBlurEffect() { Name = "Blur", BlurAmount = 2.0f, BorderMode = EffectBorderMode.Hard, Optimization = EffectOptimization.Balanced }; blurEffect.Source = new CompositionEffectSourceParameter("source"); CompositionEffectFactory blurEffectFactory = _compositor.CreateEffectFactory(blurEffect); CompositionEffectBrush blurBrush = blurEffectFactory.CreateBrush(); // Create a BackdropBrush and bind it to the EffectSourceParameter “source” CompositionBackdropBrush backdropBrush = _compositor.CreateBackdropBrush(); blurBrush.SetSourceParameter("source", backdropBrush); _blurSprite.Brush = blurBrush; }
private void InitializeBrushes() { if (this.DataContext is ViewImageEditorMetadata) { var viewImageEditorMetadata = (ViewImageEditorMetadata)this.DataContext; // noeffect brush Size imageSize; //m_noEffectBrush = CreateBrushFromAsset("xxxxx.jpg", out imageSize); m_noEffectBrush = CreateBrushFromAsset(viewImageEditorMetadata.Bitmap, out imageSize); m_imageAspectRatio = (imageSize.Width == 0 && imageSize.Height == 0) ? 1 : imageSize.Width / imageSize.Height; renderSurface.UpdateLayout(); ResizeImage(new Size(renderSurface.ActualWidth, renderSurface.ActualHeight)); // Exposure var exposureEffectDesc = new ExposureEffect { Name = "effect", Source = new CompositionEffectSourceParameter("Image") }; m_exposureEffectBrush = m_compositor.CreateEffectFactory(exposureEffectDesc, new[] { "effect.Exposure" }).CreateBrush(); ChangeExposureValue(0.5f); m_exposureEffectBrush.SetSourceParameter("Image", m_noEffectBrush); // monochromatic gray var grayscaleEffectDesc = new GrayscaleEffect { Name = "effect", Source = new CompositionEffectSourceParameter("Image") }; m_grayscaleEffectBrush = m_compositor.CreateEffectFactory(grayscaleEffectDesc).CreateBrush(); m_grayscaleEffectBrush.SetSourceParameter("Image", m_noEffectBrush); } }
public VisualImage() { InitializeComponent(); EnsureCompositor(); EnsureSurfaceFactory(); _rootVisual = ElementCompositionPreview.GetElementVisual(this); BackgroundVisual = _compositor.CreateSpriteVisual(); ForegroundVisual = _compositor.CreateSpriteVisual(); ContainerVisual = _compositor.CreateContainerVisual(); ContainerVisual.Children.InsertAtBottom(BackgroundVisual); ContainerVisual.Children.InsertAtTop(ForegroundVisual); ElementCompositionPreview.SetElementChildVisual(this, ContainerVisual); SizeChanged += (s, args) => { BackgroundVisual.Size = new Vector2((float)args.NewSize.Width, (float)args.NewSize.Height); ForegroundVisual.Size = new Vector2( (float)args.NewSize.Width - (float)ImageMargin.Left - (float)ImageMargin.Right, (float)args.NewSize.Height - (float)ImageMargin.Top - (float)ImageMargin.Bottom); }; _blurBrush = BuildBlurBrush(); Loaded += VisualImage_Loaded; Unloaded += VisualImage_Unloaded; }
public void CreateAnimation() { _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; var blurEffect = new GaussianBlurEffect { Name = "Blur", BlurAmount = 5, BorderMode = EffectBorderMode.Hard, Source = new CompositionEffectSourceParameter("backdropBrush") }; var animation = _compositor.CreateScalarKeyFrameAnimation(); animation.InsertKeyFrame(0.0f, 0.0f); animation.InsertKeyFrame(1.0f, 100.0f); animation.Duration = TimeSpan.FromSeconds(4); var effectFactory = _compositor.CreateEffectFactory(blurEffect, new[] { "Blur.BlurAmount" }); _effectBrush = effectFactory.CreateBrush(); var backdropBrush = _compositor.CreateBackdropBrush(); _effectBrush.SetSourceParameter("backdropBrush", backdropBrush); var spriteVisual = _compositor.CreateSpriteVisual(); spriteVisual.Size = new System.Numerics.Vector2((float)Err_Image.ActualWidth, (float)Err_Image.ActualHeight); spriteVisual.Brush = _effectBrush; ElementCompositionPreview.SetElementChildVisual(Err_Image, spriteVisual); spriteVisual.Brush.StartAnimation("Blur.BlurAmount", animation); }
private void Page_Loaded(object sender, RoutedEventArgs e) { //Create Visual to contain effect effectVisual = compositor.CreateSpriteVisual(); var destinationBrush = compositor.CreateBackdropBrush(); //Create the Effect you want var graphicsEffect = new GaussianBlurEffect { Name = "Blur", BlurAmount = 0f, BorderMode = EffectBorderMode.Hard, Source = new CompositionEffectSourceParameter("Background") }; effectFactory = compositor.CreateEffectFactory(graphicsEffect, new[] { "Blur.BlurAmount" }); effectBrush = effectFactory.CreateBrush(); effectBrush.SetSourceParameter("Background", destinationBrush); effectVisual.Brush = effectBrush; //By the default the Visual have the size width and height (defined in Vector 2) 0 and 0 ResizeVisual(); ElementCompositionPreview.SetElementChildVisual(Back, effectVisual); //Create Spring Animation for nature increase and decrease value _springAnimation = compositor.CreateSpringScalarAnimation(); _springAnimation.Period = TimeSpan.FromSeconds(0.5); _springAnimation.DampingRatio = 0.75f; }
public BackDrop() { #if DEBUG if (DesignMode.DesignModeEnabled) { return; } #endif m_rootVisual = ElementCompositionPreview.GetElementVisual(this as UIElement); Compositor = m_rootVisual.Compositor; m_blurVisual = Compositor.CreateSpriteVisual(); m_noiseBrush = Compositor.CreateSurfaceBrush(); CompositionEffectBrush brush = BuildBlurBrush(); brush.SetSourceParameter("source", m_compositor.CreateBackdropBrush()); m_blurBrush = brush; m_blurVisual.Brush = m_blurBrush; BlurAmount = 9; TintColor = Colors.Transparent; ElementCompositionPreview.SetElementChildVisual(this as UIElement, m_blurVisual); this.Loading += OnLoading; this.Unloaded += OnUnloaded; }
public void Do() { Visual hostVisual = ElementCompositionPreview.GetElementVisual(Err_Image); comp = ElementCompositionPreview.GetElementVisual(this).Compositor; var blurEffect = new GaussianBlurEffect { Name = "Blur", BlurAmount = (float)blur_Slider.Value, BorderMode = EffectBorderMode.Hard, Source = new CompositionEffectSourceParameter("backdropBrush") //Source = new ArithmeticCompositeEffect //{ // MultiplyAmount = 0, // Source1Amount = 0.5f, // Source2Amount = 0.5f, // Source1 = new CompositionEffectSourceParameter("backdropBrush"), // Source2 = new ColorSourceEffect // { // Color = Color.FromArgb(255,255,255,255) // } //} }; var effectFactory = comp.CreateEffectFactory(blurEffect, new[] { "Blur.BlurAmount" }); _effectBrush = effectFactory.CreateBrush(); var backdropBrush = comp.CreateBackdropBrush(); _effectBrush.SetSourceParameter("backdropBrush", backdropBrush); var blurVisual = comp.CreateSpriteVisual(); blurVisual.Size = new System.Numerics.Vector2((float)Err_Image.ActualWidth, (float)Err_Image.ActualHeight); blurVisual.Brush = _effectBrush; ElementCompositionPreview.SetElementChildVisual(Err_Image, blurVisual); }
private void MainPage_Loaded(object sender, RoutedEventArgs e) { // Initialize Composition UI infrastructure. _root = Container.GetVisual(); _compositor = _root.Compositor; _imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor); // Hook the sprite visual into the XAML visual tree. _spriteVisual = _compositor.CreateSpriteVisual(); var side = (float)Math.Min(Presenter.ActualWidth, Presenter.ActualHeight); _spriteVisual.Size = new Vector2(side, side); _root.Children.InsertAtTop(_spriteVisual); // Create the effect, but don't specify the properties yet. var temperatureAndTintEffect = new TemperatureAndTintEffect { Name = "temperatureAndtint", Source = new CompositionEffectSourceParameter("source") }; // Strongly typed version of the "temperatureAndtint.Temperature" string _temperatureParameter = temperatureAndTintEffect.Name + "." + nameof(temperatureAndTintEffect.Temperature); // Compile the effect var effectFactory = _compositor.CreateEffectFactory( temperatureAndTintEffect, new[] { _temperatureParameter, "temperatureAndtint.Tint" }); // Create and apply the brush. _brush = effectFactory.CreateBrush(); _spriteVisual.Brush = _brush; ColorWheelButton.IsChecked = true; }
public BackDrop() { if (ApiInformation.IsMethodPresent("Windows.UI.Composition.Compositor", "CreateBackdropBrush")) { m_rootVisual = ElementCompositionPreview.GetElementVisual(this as UIElement); Compositor = m_rootVisual.Compositor; m_blurBrush = BuildBlurBrush(); m_blurBrush.SetSourceParameter("source", m_compositor.CreateBackdropBrush()); m_blurVisual = Compositor.CreateSpriteVisual(); m_blurVisual.Brush = m_blurBrush; BlurAmount = 9; TintColor = Colors.Transparent; ElementCompositionPreview.SetElementChildVisual(this as UIElement, m_blurVisual); this.Loading += OnLoading; this.Unloaded += OnUnloaded; } else { } }
private void MainPage_Loaded(object sender, RoutedEventArgs e) { // Initialize Composition UI infrastructure. _root = Container.GetVisual(); _compositor = _root.Compositor; _imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor); // Hook the sprite visual into the XAML visual tree. _spriteVisual = _compositor.CreateSpriteVisual(); var side = (float)Math.Min(Presenter.ActualWidth, Presenter.ActualHeight); _spriteVisual.Size = new Vector2(side, side); _root.Children.InsertAtTop(_spriteVisual); // Create the effect, but don't specify the Angle yet. var hueRotationEffect = new HueRotationEffect { Name = "hueRotation", Source = new CompositionEffectSourceParameter("source") }; // Compile the effect var effectFactory = _compositor.CreateEffectFactory(hueRotationEffect, new[] { "hueRotation.Angle" }); // Create and apply the brush. _brush = effectFactory.CreateBrush(); _spriteVisual.Brush = _brush; ColorWheelButton.IsChecked = true; }
private async void ApplyEffect(CompositionImage image) { Task <CompositionDrawingSurface> task = null; // If we've requested a load time effect input, kick it off now if (_currentTechnique.LoadTimeEffectHandler != null) { task = SurfaceLoader.LoadFromUri(image.Source, Size.Empty, _currentTechnique.LoadTimeEffectHandler); } // Create the new brush, set the inputs and set it on the image CompositionEffectBrush brush = _currentTechnique.CreateBrush(); brush.SetSourceParameter("ImageSource", image.SurfaceBrush); image.Brush = brush; // If we've got an active task, wait for it to finish if (task != null) { CompositionDrawingSurface effectSurface = await task; // Set the effect surface as input brush.SetSourceParameter("EffectSource", _compositor.CreateSurfaceBrush(effectSurface)); } }
private void Load_Completed(LoadedImageSurface sender, LoadedImageSourceLoadCompletedEventArgs e) { IsImageLoading = false; if (e.Status == LoadedImageSourceLoadStatus.Success) { var compositor = Window.Current.Compositor; var brush = compositor.CreateSurfaceBrush(_surface); brush.Stretch = CompositionStretch.UniformToFill; // Create effects chain. saturationEffect = new SaturationEffect() { Name = "SaturationEffect", Saturation = (float)SaturationAmount, Source = new CompositionEffectSourceParameter("image") }; contrastEffect = new ContrastEffect() { Name = "ContrastEffect", Contrast = (float)ContrastAmount, Source = saturationEffect }; exposureEffect = new ExposureEffect() { Name = "ExposureEffect", Source = contrastEffect, Exposure = (float)ExposureAmount, }; temperatureAndTintEffect = new TemperatureAndTintEffect() { Name = "TemperatureAndTintEffect", Source = exposureEffect, Temperature = (float)TemperatureAmount, Tint = (float)TintAmount }; graphicsEffect = new GaussianBlurEffect() { Name = "Blur", Source = temperatureAndTintEffect, BlurAmount = (float)BlurAmount, BorderMode = EffectBorderMode.Hard, }; var graphicsEffectFactory = compositor.CreateEffectFactory(graphicsEffect, new[] { "SaturationEffect.Saturation", "ExposureEffect.Exposure", "Blur.BlurAmount", "TemperatureAndTintEffect.Temperature", "TemperatureAndTintEffect.Tint", "ContrastEffect.Contrast" }); combinedBrush = graphicsEffectFactory.CreateBrush(); combinedBrush.SetSourceParameter("image", brush); // Composition Brush is what is being applied to the UI Element. CompositionBrush = combinedBrush; } else { LoadImageFromPath("ms-appx:///Assets/StoreLogo.png"); } }
private void CreateBrush() { effectBrush = effectFactory.CreateBrush(); effectBrush.SetSourceParameter(EffectSource, surfaceBrush); effectBrush.Properties.InsertScalar(TemperatureEffectPath, 0f); effectBrush.Properties.InsertScalar(TintEffectPath, 0f); }
private void InitializeCompositor() { compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; InitializeEffects(); MainImage.Source = item.ImageSource; MainImage.InvalidateArrange(); var destinationBrush = compositor.CreateBackdropBrush(); var graphicsEffectFactory = compositor.CreateEffectFactory(graphicsEffect, new[] { "SaturationEffect.Saturation", "ExposureEffect.Exposure", "Blur.BlurAmount", "TemperatureAndTintEffect.Temperature", "TemperatureAndTintEffect.Tint", "ContrastEffect.Contrast" }); combinedBrush = graphicsEffectFactory.CreateBrush(); combinedBrush.SetSourceParameter("Backdrop", destinationBrush); var effectSprite = compositor.CreateSpriteVisual(); effectSprite.Size = new Vector2((float)item.ImageSource.PixelWidth, (float)item.ImageSource.PixelHeight); effectSprite.Brush = combinedBrush; ElementCompositionPreview.SetElementChildVisual(MainImage, effectSprite); editingInitialized = true; }
//LightingTypes _selectedLight = LightingTypes.PointDiffuse; private void SetImageEffect(CompositionImage image) { if (_effectFactory == null) { return; } // Create the effect brush and bind the normal map CompositionEffectBrush brush = _effectFactory.CreateBrush(); //ComboBoxItem item = LightingSelection.SelectedValue as ComboBoxItem; //switch ((LightingTypes)item.Tag) switch (SelectedLight) { case LightingTypes.SpotLightSpecular: case LightingTypes.PointSpecular: case LightingTypes.DistantDiffuse: case LightingTypes.DistantSpecular: brush.SetSourceParameter("NormalMap", _circleNormalsBrush); break; default: brush.SetSourceParameter("NormalMap", _flatNormalsBrush); break; } // Update the CompositionImage to use the custom effect brush image.Brush = brush; }
/// <summary> /// Assign a given CompositionEffectBrush to our video visual. The caller is in charge /// of assigning the video content to the brush. /// </summary> /// <param name="brush">The effect brush to apply to the video visual.</param> private void SetEffect(CompositionEffectBrush brush) { if (_videoVisual != null) { _videoVisual.Brush = brush; } }
public MainPage() { this.InitializeComponent(); MainGrid.SizeChanged += OnMainGridSizeChanged; compositor = ElementCompositionPreview.GetElementVisual(MainGrid).Compositor; // we create the effect. // Notice the Source parameter definition. Here we tell the effect that the source will come from another element/object var blurEffect = new GaussianBlurEffect { Name = "Blur", Source = new CompositionEffectSourceParameter("background"), BlurAmount = 100f, BorderMode = EffectBorderMode.Hard, }; // we convert the effect to a blur that can be used to paint the visual layer var blurEffectFactory = compositor.CreateEffectFactory(blurEffect); brush = blurEffectFactory.CreateBrush(); // We create a special brush to get the image output of the previous layer. // we are basically chaining the layer (xaml grid -> rendered bitmap of the grid -> blur effect -> screen) var destinationBrush = compositor.CreateBackdropBrush(); brush.SetSourceParameter("background", destinationBrush); // we create the visual sprite that will hold our generated bitmap (the blurred grid) // Visual Sprite are "raw" elements so there is no automatic layouting. You have to specify the size yourself var blurSprite = compositor.CreateSpriteVisual(); blurSprite.Size = new Vector2((float)MainGrid.ActualWidth, (float)MainGrid.ActualHeight); blurSprite.Brush = brush; // we add our sprite to the rendering pipeline ElementCompositionPreview.SetElementChildVisual(MainGrid, blurSprite); }
protected override void OnConnected() { // return if Uri String is null or empty if (String.IsNullOrEmpty(ImageUriString)) { return; } Compositor compositor = Window.Current.Compositor; // Use LoadedImageSurface API to get ICompositionSurface from image uri provided _surface = LoadedImageSurface.StartLoadFromUri(new Uri(ImageUriString)); // Load Surface onto SurfaceBrush _surfaceBrush = compositor.CreateSurfaceBrush(_surface); _surfaceBrush.Stretch = CompositionStretch.UniformToFill; // CompositionCapabilities: Are Tint+Temperature and Saturation supported? bool usingFallback = !CompositionCapabilities.GetForCurrentView().AreEffectsSupported(); if (usingFallback) { // If Effects are not supported, Fallback to image without effects CompositionBrush = _surfaceBrush; return; } // Define Effect graph IGraphicsEffect graphicsEffect = new SaturationEffect { Name = "Saturation", Saturation = 0.3f, Source = new TemperatureAndTintEffect { Name = "TempAndTint", Temperature = 0, Source = new CompositionEffectSourceParameter("Surface"), } }; // Create EffectFactory and EffectBrush CompositionEffectFactory effectFactory = compositor.CreateEffectFactory(graphicsEffect, new[] { "TempAndTint.Temperature" }); CompositionEffectBrush effectBrush = effectFactory.CreateBrush(); effectBrush.SetSourceParameter("Surface", _surfaceBrush); // Set EffectBrush to paint Xaml UIElement CompositionBrush = effectBrush; // Trivial looping animation to demonstrate animated effect ScalarKeyFrameAnimation tempAnim = compositor.CreateScalarKeyFrameAnimation(); tempAnim.InsertKeyFrame(0, 0); tempAnim.InsertKeyFrame(0.5f, 1f); tempAnim.InsertKeyFrame(1, 0); tempAnim.Duration = TimeSpan.FromSeconds(5); tempAnim.IterationBehavior = Windows.UI.Composition.AnimationIterationBehavior.Forever; effectBrush.Properties.StartAnimation("TempAndTint.Temperature", tempAnim); }
async Task CreateTintEffectBrushAsync(Uri uri) { Xamarin.Forms.Image element = this.Element as Xamarin.Forms.Image; if (Control == null || Element == null || element.Width < 0 || element.Height < 0) { return; } SetupCompositor(); spriteVisual = compositor.CreateSpriteVisual(); spriteVisual.Size = new Vector2((float)element.Width, (float)element.Height); imageSurface = await generator.CreateImageSurfaceAsync(uri, new Windows.Foundation.Size(element.Width, element.Height), ImageSurfaceOptions.DefaultOptimized); CompositionSurfaceBrush surfaceBrush = compositor.CreateSurfaceBrush(imageSurface.Surface); CompositionBrush targetBrush = surfaceBrush; if (this.TintColor == Color.Transparent) { // Don't apply tint effect effectBrush = null; } else { // Set target brush to tint effect brush Windows.UI.Color nativeColor = GetNativeColor(this.TintColor); IGraphicsEffect graphicsEffect = new CompositeEffect { Mode = CanvasComposite.DestinationIn, Sources = { new ColorSourceEffect { Name = "colorSource", Color = nativeColor }, new CompositionEffectSourceParameter("mask") } }; CompositionEffectFactory effectFactory = compositor.CreateEffectFactory(graphicsEffect, new[] { "colorSource.Color" }); effectBrush = effectFactory.CreateBrush(); effectBrush.SetSourceParameter("mask", surfaceBrush); SetTint(nativeColor); targetBrush = effectBrush; } spriteVisual.Brush = targetBrush; ElementCompositionPreview.SetElementChildVisual(Control, spriteVisual); }
private void ApplyInternal( float blurAmount) { // SOURCE: https://msdn.microsoft.com/en-us/windows/uwp/graphics/using-the-visual-layer-with-xaml // Get the host visual and compositor Visual hostVisual = ElementCompositionPreview.GetElementVisual(this._foregroundElement); Compositor compositor = hostVisual.Compositor; // Create a blur effect this._blurEffect = new GaussianBlurEffect { BlurAmount = blurAmount, BorderMode = EffectBorderMode.Hard, //Source = new CompositionEffectSourceParameter("backdropBrush"), Source = new ArithmeticCompositeEffect { MultiplyAmount = 0, Source1Amount = 0.5f, Source2Amount = 0.5f, Source1 = new CompositionEffectSourceParameter("backdropBrush"), Source2 = new ColorSourceEffect { Color = global::Windows.UI.Color.FromArgb(255, 0xee, 0xee, 0xee), } } }; // Create an instance of the effect using (var effectFactory = compositor.CreateEffectFactory(this._blurEffect)) { this._effectBrush = effectFactory.CreateBrush(); } // Set the effect source to a CompositionBackdropBrush this._backdropBrush = compositor.CreateBackdropBrush(); this._effectBrush.SetSourceParameter("backdropBrush", this._backdropBrush); // Get any existing child sprite visual this._blurVisual = (SpriteVisual)ElementCompositionPreview.GetElementChildVisual(this._foregroundElement); if (null == this._blurVisual) { // Create a sprite visual to contain the effect this._blurVisual = compositor.CreateSpriteVisual(); this._blurVisual.Brush = this._effectBrush; // Add the sprite visual as a child of the host visual in the visual tree ElementCompositionPreview.SetElementChildVisual(this._foregroundElement, this._blurVisual); } else { this._blurVisual.Brush = this._effectBrush; } // Make sure size of the host and effect visuals always stay in sync this._bindSizeAnimation = compositor.CreateExpressionAnimation("hostVisual.Size"); this._bindSizeAnimation.SetReferenceParameter("hostVisual", hostVisual); this._blurVisual.StartAnimation("Size", this._bindSizeAnimation); }
public override CompositionEffectBrush CreateBrush() { CompositionEffectBrush brush = base.CreateBrush(); brush.SetSourceParameter("LightMap", _lightMap.Brush); return(brush); }
public CompositionBrush CreateRevealBrush(Color color) { var effectFactory = _createRevealBrushCompositionEffectFactory(); _revealBrush = effectFactory.CreateBrush(); SetColor(color); return(_revealBrush); }
/// <summary> /// Returns the effect brush for this model. If a brush has not beeen created, one is created /// given CreateEffectFactory has been assigned. /// </summary> /// <returns>CompositionEffectBrush</returns> public CompositionEffectBrush GetEffectBrush() { if (_brush == null && CreateEffectFactory != null) { if (_factory == null) { _factory = CreateEffectFactory(); } _brush = _factory.CreateBrush(); } return _brush; }
private void ReleaseContent() { if (_surface != null) { _surface.Dispose(); _surface = null; } if (_effectSurface != null) { _effectSurface.Dispose(); _effectSurface = null; } if (_effectBrush != null) { _effectBrush.Dispose(); _effectBrush = null; } }
/// <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(); }
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); }
private void CreateBrush() { effectBrush = effectFactory.CreateBrush(); effectBrush.SetSourceParameter(EffectSource, surfaceBrush); effectBrush.Properties.InsertScalar(SaturationEffectPath, 0f); }
/// <summary> /// Create the _frontVisual and the animations that drive it. /// </summary> /// <param name="scrollProperties">A property set who has Translation.Y specified - typically the return from ElementCompositionPreview.GetScrollViewerManipulationPropertySet(...).</param> /// <param name="maskedBrush">This is the brush that will be set on _frontVisual</param> private void InitializeFrontVisual(CompositionPropertySet scrollProperties, CompositionEffectBrush maskedBrush) { // // Create the _frontVisual, set the brush on it, and attach it to the scrollViewer. Setting it as the // child visual on scrollviewer will put it in front of all the scrollViewer content. // _frontVisual = _compositor.CreateSpriteVisual(); _frontVisual.Brush = maskedBrush; ElementCompositionPreview.SetElementChildVisual(MainGrid, _frontVisual); // // "Terms" in the following expression: // // (CrossoverTranslation + scrollingProperties.Translation.Y)/CrossoverTranslation // // Since scrollingProperties.Translation.Y is negative. This creates a normalized value that goes from // 0 to 1 between no scrolling and the CrossoverTranslation. // _frontPropertiesScalarScaleAnimation = _compositor.CreateExpressionAnimation( "Lerp(minClamp, maxClamp, Clamp((CrossoverTranslation + scrollingProperties.Translation.Y)/CrossoverTranslation,0,1))" ); _frontPropertiesScalarScaleAnimation.SetReferenceParameter("scrollingProperties", scrollProperties); _frontPropertiesScalarScaleAnimation.SetScalarParameter("minClamp", _finalScaleAmount); _frontPropertiesScalarScaleAnimation.SetScalarParameter("maxClamp", _initialScaleAmount); // // The previous equation calculates a scalar which is later bound to ScalarScale in FrontVisual's Properties. // This equation uses that scalar to construct a new vector3 to set to animate the scale of the visual itself. // var vector3ScaleAnimation = _compositor.CreateExpressionAnimation("Vector3(Properties.ScalarScale, Properties.ScalarScale, 1)"); _frontVisual.Properties.InsertScalar("ScalarScale", 1); vector3ScaleAnimation.SetReferenceParameter("Properties", _frontVisual.Properties); _frontVisual.StartAnimation("Scale", vector3ScaleAnimation); // // This equation controls whether or not the FrontVisual is visibile via opacity. It uses a simple ternary operator // to pick between 100% and 0% opacity based on the position being before the crossover point. // _frontVisibilityAnimation = _compositor.CreateExpressionAnimation("-scrollingProperties.Translation.Y <= CrossoverTranslation ? 1 : 0"); _frontVisibilityAnimation.SetReferenceParameter("scrollingProperties", scrollProperties); _frontTranslationAnimation = _compositor.CreateExpressionAnimation("scrollingProperties.Translation.Y > 0 ? BaseOffset : BaseOffset-scrollingProperties.Translation.Y"); _frontTranslationAnimation.SetReferenceParameter("scrollingProperties", scrollProperties); }
/// <summary> /// Create the _backVisual and the animations that drive it. /// </summary> /// <param name="scrollProperties">A property set who has Translation.Y specified - typically the return from ElementCompositionPreview.GetScrollViewerManipulationPropertySet(...).</param> /// <param name="maskedBrush">This is the brush that will be set on _frontVisual</param> private void InitializeBehindVisual(CompositionPropertySet scrollProperties, CompositionEffectBrush maskedBrush) { // // Create the _frontVisual, set the brush on it, and attach it to the BackGrid. BackGrid is an empty grid // that is visually behind the profile background (the waves). Therefore, setting it as the // child visual on the BackGrid will put it behind all the scrollViewer content. // _backVisual = _compositor.CreateSpriteVisual(); _backVisual.Brush = maskedBrush; ElementCompositionPreview.SetElementChildVisual(BackGrid, _backVisual); // // This equation controls whether or not the FrontVisual is visibile via opacity. It uses a simple ternary operator // to pick between 100% and 0% opacity based on the position being after the crossover point. // _backVisual.Scale = new Vector3(_finalScaleAmount, _finalScaleAmount, 1); _behindOpacityAnimation = _compositor.CreateExpressionAnimation("-scrollingProperties.Translation.Y <= CrossoverTranslation ? 0 : 1"); _behindOpacityAnimation.SetReferenceParameter("scrollingProperties", scrollProperties); // // "Terms" and explanation of the following expression: // // (initialOffset - scrollingProperties.Translation.Y) // // Since _backVisual is a child of the scroller, the initial position minus the scrolling offset keeps the content // in its original location. // // 2 * (CrossoverTranslation + scrollingProperties.Translation.Y) // // Since scrollingProperties.Translation.Y is negative when this expression is visibile, this term calculates the // distance past the crossover point and scales it. The scale causes the content to move faster than the scrolling. // Since this term evaluates to zero at the crossover point and the term above keeps the content from moving, when // the visibility swaps between frontVisual and backVisual, they are perfectly aligned. // _behindTranslateAnimation = _compositor.CreateExpressionAnimation( "(BaseOffset - scrollingProperties.Translation.Y) + 2 * (CrossoverTranslation + scrollingProperties.Translation.Y)"); _behindTranslateAnimation.SetReferenceParameter("scrollingProperties", scrollProperties); }
/// <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); }
private void CreateBrush() { effectBrush = effectFactory.CreateBrush(); effectBrush.SetSourceParameter(EffectSource, surfaceBrush); effectBrush.Properties.InsertScalar(RedExponentEffectPath, 1f); effectBrush.Properties.InsertScalar(GreenExponentEffectPath, 1f); effectBrush.Properties.InsertScalar(BlueExponentEffectPath, 1f); }
private ContainerVisual AddLayerVisual( CompositionEffectBrush effectBrush, Vector2 size, Vector3 offset, ContainerVisual parent) { var layerVisual = _compositor.CreateLayerVisual(); layerVisual.Effect = effectBrush; layerVisual.Size = size; layerVisual.Offset = offset; parent.Children.InsertAtTop(layerVisual); return layerVisual; }
private void InitializeBrush(IGraphicsEffect effect, String uri) { Brush = Compositor.CreateEffectFactory(effect, new[] { "effect.Source1Amount", "effect.Source2Amount", } ).CreateBrush(); SetForeground(uri); }
public async void SetEffectBrush(CompositionEffectBrush brush) { // Release previous brush if set if (_effectBrush != null) { _effectBrush.Dispose(); _effectBrush = null; } if (_effectSurface != null) { _effectSurface.Dispose(); _effectSurface = null; } _effectBrush = brush; // Set the new brush if (_sprite != null) { // Release current brush if (_sprite.Brush != null) { _sprite.Brush.Dispose(); } if (_surface != null) { // If the effect brush is cleared, create a surface brush if (_effectBrush == null) { _sprite.Brush = _compositor.CreateSurfaceBrush(_surface); } else { _effectBrush.SetSourceParameter("ImageSource", _compositor.CreateSurfaceBrush(_surface)); if (_loadEffectDelegate != null) { _effectSurface = await SurfaceLoader.LoadFromUri(_uri, Size.Empty, _loadEffectDelegate); _effectBrush.SetSourceParameter("EffectSource", _compositor.CreateSurfaceBrush(_effectSurface)); } _sprite.Brush = _effectBrush; } } } }
private void BlendSelection_SelectionChanged(object sender, SelectionChangedEventArgs e) { ComboBoxItem item = BlendSelection.SelectedValue as ComboBoxItem; BlendEffectMode blendmode = (BlendEffectMode)item.Tag; // Create a chained effect graph using a BlendEffect, blending color and blur var graphicsEffect = new BlendEffect { Mode = blendmode, Background = new ColorSourceEffect() { Name = "Tint", Color = Tint.Color, }, Foreground = new GaussianBlurEffect() { Name = "Blur", Source = new CompositionEffectSourceParameter("Backdrop"), BlurAmount = (float)BlurAmount.Value, BorderMode = EffectBorderMode.Hard, } }; var blurEffectFactory = _compositor.CreateEffectFactory(graphicsEffect, new[] { "Blur.BlurAmount", "Tint.Color"}); // Create EffectBrush, BackdropBrush and SpriteVisual _brush = blurEffectFactory.CreateBrush(); // If the animation is running, restart it on the new brush if (AnimateToggle.IsOn) { StartBlurAnimation(); } var destinationBrush = _compositor.CreateBackdropBrush(); _brush.SetSourceParameter("Backdrop", destinationBrush); var blurSprite = _compositor.CreateSpriteVisual(); blurSprite.Size = new Vector2((float)BackgroundImage.ActualWidth, (float)BackgroundImage.ActualHeight); blurSprite.Brush = _brush; ElementCompositionPreview.SetElementChildVisual(BackgroundImage, blurSprite); }
/// <summary> /// Assign a given CompositionEffectBrush to our video visual. The caller is in charge /// of assigning the video content to the brush. /// </summary> /// <param name="brush">The effect brush to apply to the video visual.</param> private void SetEffect(CompositionEffectBrush brush) { if (_videoVisual != null) { _videoVisual.Brush = brush; } }
private ContainerVisual AddLayerVisual( CompositionEffectBrush effectBrush, Vector2 size, Windows.UI.Xaml.UIElement parent) { var layerVisual = _compositor.CreateLayerVisual(); layerVisual.Effect = effectBrush; layerVisual.Size = size; ElementCompositionPreview.SetElementChildVisual(parent, layerVisual); return layerVisual; }
private void MainGridLoaded(object sender, RoutedEventArgs e) { m_compositor = ElementCompositionPreview.GetElementVisual(MainGrid).Compositor; m_root = m_compositor.CreateContainerVisual(); ElementCompositionPreview.SetElementChildVisual(MainGrid, m_root); Size imageSize; m_noEffectBrush = CreateBrushFromAsset( "Bruno'sFamily2015 (13)-X2.jpg", out imageSize); m_imageAspectRatio = (imageSize.Width == 0 && imageSize.Height == 0) ? 1 : imageSize.Width / imageSize.Height; m_sprite = m_compositor.CreateSpriteVisual(); ResizeImage(new Size(MainGrid.ActualWidth, MainGrid.ActualHeight)); m_root.Children.InsertAtTop(m_sprite); // Image with alpha channel as an mask. var alphaMaskEffectDesc = new CompositeEffect { Mode = CanvasComposite.DestinationIn, Sources = { new CompositionEffectSourceParameter("Image"), new Transform2DEffect { Name = "MaskTransform", Source = new CompositionEffectSourceParameter("Mask") } } }; m_alphaMaskEffectBrush = m_compositor.CreateEffectFactory( alphaMaskEffectDesc, new[] { "MaskTransform.TransformMatrix" } ).CreateBrush(); m_alphaMaskEffectBrush.SetSourceParameter( "Image", m_noEffectBrush); m_alphaMaskEffectBrush.SetSourceParameter( "Mask", CreateBrushFromAsset("CircleMask.png")); // Arithmetic operations between two images. var arithmeticEffectDesc = new ArithmeticCompositeEffect { Name = "effect", ClampOutput = false, Source1 = new CompositionEffectSourceParameter("Source1"), Source2 = new CompositionEffectSourceParameter("Source2") }; m_arithmeticEffectBrush = m_compositor.CreateEffectFactory( arithmeticEffectDesc, new[] { "effect.MultiplyAmount", "effect.Source1Amount", "effect.Source2Amount", "effect.Offset" } ).CreateBrush(); m_arithmeticEffectBrush.SetSourceParameter( "Source1", m_noEffectBrush); m_arithmeticEffectBrush.SetSourceParameter( "Source2", CreateBrushFromAsset("_P2A8041.jpg")); // Creates a blend effect that combines two images. var foregroundBrush = CreateBrushFromAsset("Checkerboard_100x100.png"); m_blendEffectBrushes = new CompositionEffectBrush[m_supportedBlendModes.Length]; for (int i = 0; i < m_supportedBlendModes.Length; i++) { var blendEffectDesc = new BlendEffect { Mode = m_supportedBlendModes[i], Background = new CompositionEffectSourceParameter("Background"), Foreground = new CompositionEffectSourceParameter("Foreground") }; m_blendEffectBrushes[i] = m_compositor.CreateEffectFactory( blendEffectDesc ).CreateBrush(); m_blendEffectBrushes[i].SetSourceParameter( "Background", m_noEffectBrush); m_blendEffectBrushes[i].SetSourceParameter( "Foreground", foregroundBrush); } // Generates an image containing a solid color. var colorSourceEffectDesc = new ColorSourceEffect // FloodEffect { Name = "effect" }; m_colorSourceEffectBrush = m_compositor.CreateEffectFactory( colorSourceEffectDesc, new[] { "effect.Color" } ).CreateBrush(); // Changes the contrast of an image. var contrastEffectDesc = new ContrastEffect { Name = "effect", Source = new CompositionEffectSourceParameter("Image") }; m_contrastEffectBrush = m_compositor.CreateEffectFactory( contrastEffectDesc, new[] { "effect.Contrast" } ).CreateBrush(); m_contrastEffectBrush.SetSourceParameter( "Image", m_noEffectBrush); // Changes the exposure of an image. var exposureEffectDesc = new ExposureEffect { Name = "effect", Source = new CompositionEffectSourceParameter("Image") }; m_exposureEffectBrush = m_compositor.CreateEffectFactory( exposureEffectDesc, new[] { "effect.Exposure" } ).CreateBrush(); m_exposureEffectBrush.SetSourceParameter( "Image", m_noEffectBrush); // Alters the colors of an image by applying a per-channel gamma transfer function. var gammaTransferEffectDesc = new GammaTransferEffect { Name = "effect", RedDisable = false, GreenDisable = false, BlueDisable = false, AlphaDisable = false, Source = new CompositionEffectSourceParameter("Image") }; m_gammaTransferEffectBrush = m_compositor.CreateEffectFactory( gammaTransferEffectDesc, new[] { "effect.RedAmplitude", "effect.RedExponent", "effect.RedOffset", "effect.GreenAmplitude", "effect.GreenExponent", "effect.GreenOffset", "effect.BlueAmplitude", "effect.BlueExponent", "effect.BlueOffset" } ).CreateBrush(); m_gammaTransferEffectBrush.SetSourceParameter( "Image", m_noEffectBrush); // Converts an image to monochromatic gray. var grayscaleEffectDesc = new GrayscaleEffect { Name = "effect", Source = new CompositionEffectSourceParameter("Image") }; m_grayscaleEffectBrush = m_compositor.CreateEffectFactory( grayscaleEffectDesc ).CreateBrush(); m_grayscaleEffectBrush.SetSourceParameter( "Image", m_noEffectBrush); // Alters the color of an image by rotating its hue values. var hueRotationEffectDesc = new HueRotationEffect { Name = "effect", Source = new CompositionEffectSourceParameter("Image") }; m_hueRotationEffectBrush = m_compositor.CreateEffectFactory( hueRotationEffectDesc, new[] { "effect.Angle" } ).CreateBrush(); m_hueRotationEffectBrush.SetSourceParameter( "Image", m_noEffectBrush); // Inverts the colors of an image. var invertEffectDesc = new InvertEffect { Name = "effect", Source = new CompositionEffectSourceParameter("Image") }; m_invertEffectBrush = m_compositor.CreateEffectFactory( invertEffectDesc ).CreateBrush(); m_invertEffectBrush.SetSourceParameter( "Image", m_noEffectBrush); // Alters the saturation of an image. var saturationEffectDesc = new SaturationEffect { Name = "effect", Source = new CompositionEffectSourceParameter("Image") }; m_saturateEffectBrush = m_compositor.CreateEffectFactory( saturationEffectDesc, new[] { "effect.Saturation" } ).CreateBrush(); m_saturateEffectBrush.SetSourceParameter( "Image", m_noEffectBrush); // Converts an image to sepia tones. var supportedAlphaModes = new[] { CanvasAlphaMode.Premultiplied, CanvasAlphaMode.Straight }; m_sepiaEffectBrushes = new CompositionEffectBrush[supportedAlphaModes.Length]; for (int i = 0; i < supportedAlphaModes.Length; i++) { var sepiaEffectDesc = new SepiaEffect { Name = "effect", AlphaMode = supportedAlphaModes[i], Source = new CompositionEffectSourceParameter("Image") }; m_sepiaEffectBrushes[i] = m_compositor.CreateEffectFactory( sepiaEffectDesc, new[] { "effect.Intensity" } ).CreateBrush(); m_sepiaEffectBrushes[i].SetSourceParameter( "Image", m_noEffectBrush); } // Adjusts the temperature and/or tint of an image. var temperatureAndTintEffectDesc = new TemperatureAndTintEffect { Name = "effect", Source = new CompositionEffectSourceParameter("Image") }; m_temperatureAndTintEffectBrush = m_compositor.CreateEffectFactory( temperatureAndTintEffectDesc, new[] { "effect.Temperature", "effect.Tint" } ).CreateBrush(); m_temperatureAndTintEffectBrush.SetSourceParameter( "Image", m_noEffectBrush); // Applies a 2D affine transform matrix to an image. var transform2DEffectDesc = new Transform2DEffect { TransformMatrix = new Matrix3x2( -1, 0, 0, 1, m_sprite.Size.X, 0), Source = new CompositionEffectSourceParameter("Image") }; m_transform2DEffectBrush = m_compositor.CreateEffectFactory( transform2DEffectDesc ).CreateBrush(); m_transform2DEffectBrush.SetSourceParameter( "Image", m_noEffectBrush); // For simplying UI states switch, put effect parameter grids in an array m_effectParamsGrids = new Grid[(int)EffectType.NumEffectTypes]; m_effectParamsGrids[(int)EffectType.NoEffect] = null; m_effectParamsGrids[(int)EffectType.AlphaMask] = AlphaMaskParams; m_effectParamsGrids[(int)EffectType.Arithmetic] = ArithmeticParams; m_effectParamsGrids[(int)EffectType.Blend] = BlendParams; m_effectParamsGrids[(int)EffectType.ColorSource] = ColorSourceParams; m_effectParamsGrids[(int)EffectType.Contrast] = ContrastParams; m_effectParamsGrids[(int)EffectType.Exposure] = ExposureParams; m_effectParamsGrids[(int)EffectType.GammaTransfer] = GammaTransferParams; m_effectParamsGrids[(int)EffectType.Grayscale] = null; m_effectParamsGrids[(int)EffectType.HueRotation] = HueRotationParams; m_effectParamsGrids[(int)EffectType.Invert] = null; m_effectParamsGrids[(int)EffectType.Saturation] = SaturationParams; m_effectParamsGrids[(int)EffectType.Sepia] = SepiaParams; m_effectParamsGrids[(int)EffectType.TemperatureAndTint] = TemperatureAndTintParams; m_effectParamsGrids[(int)EffectType.Transform2D] = null; // Same as grids m_effectBrushes = new CompositionBrush[(int)EffectType.NumEffectTypes]; m_effectBrushes[(int)EffectType.NoEffect] = m_noEffectBrush; m_effectBrushes[(int)EffectType.AlphaMask] = m_alphaMaskEffectBrush; m_effectBrushes[(int)EffectType.Arithmetic] = m_arithmeticEffectBrush; m_effectBrushes[(int)EffectType.Blend] = m_blendEffectBrushes[m_activeBlendMode]; m_effectBrushes[(int)EffectType.ColorSource] = m_colorSourceEffectBrush; m_effectBrushes[(int)EffectType.Contrast] = m_contrastEffectBrush; m_effectBrushes[(int)EffectType.Exposure] = m_exposureEffectBrush; m_effectBrushes[(int)EffectType.GammaTransfer] = m_gammaTransferEffectBrush; m_effectBrushes[(int)EffectType.Grayscale] = m_grayscaleEffectBrush; m_effectBrushes[(int)EffectType.HueRotation] = m_hueRotationEffectBrush; m_effectBrushes[(int)EffectType.Invert] = m_invertEffectBrush; m_effectBrushes[(int)EffectType.Saturation] = m_saturateEffectBrush; m_effectBrushes[(int)EffectType.Sepia] = m_sepiaEffectBrushes[m_activeSepiaAlphaMode]; m_effectBrushes[(int)EffectType.TemperatureAndTint] = m_temperatureAndTintEffectBrush; m_effectBrushes[(int)EffectType.Transform2D] = m_transform2DEffectBrush; this.InitializeValues(); }
private void CreateBrush() { effectBrush = effectFactory.CreateBrush(); effectBrush.SetSourceParameter(EffectSource, surfaceBrush); effectBrush.Properties.InsertScalar(IntensityEffectPath, 0.5f); }
public void Dispose() { imageFactory = null; imageSource = null; if (effect != null) { effect.Dispose(); effect = null; } if (surfaceBrush != null) { surfaceBrush.Surface = null; surfaceBrush.Dispose(); surfaceBrush = null; } //if (visual != null) //{ // if(spriteVisual!=null) visual.Children.Remove(spriteVisual); // visual.Dispose(); // visual = null; //} if (effectBrush != null) { effectBrush.SetSourceParameter(EffectSource, null); effectBrush.Dispose(); effectBrush = null; } if (spriteVisual != null) { spriteVisual.Brush = null; spriteVisual.Dispose(); spriteVisual = null; } }
private void CreateBrush() { effectBrush = effectFactory.CreateBrush(); effectBrush.SetSourceParameter(EffectSource, surfaceBrush); }
/// <summary> /// Disposes the resources /// </summary> public void Dispose() { // Clean up resources _compositor = null; Source = null; DataContext = null; Foreground = null; Background = null; _scheduledObject = null; _currentObject = null; // Clean up Composition Objects _imageSurface?.Dispose(); _imageSurface = null; _nextImageSurface?.Dispose(); _nextImageSurface = null; _frameLayerMask?.Dispose(); _frameLayerMask = null; _placeholderContentMask?.Dispose(); _placeholderContentMask = null; _placeholderContentBrush?.Dispose(); _placeholderContentBrush = null; _nextSurfaceBrush?.Dispose(); _nextSurfaceBrush = null; _rootContainer?.Dispose(); _rootContainer = null; _shadowVisual?.Dispose(); _shadowVisual = null; _frameLayer?.Dispose(); _frameLayer = null; _frameBackgroundVisual?.Dispose(); _frameBackgroundVisual = null; _placeholderBackgroundVisual?.Dispose(); _placeholderBackgroundVisual = null; _placeholderContentVisual?.Dispose(); _placeholderContentVisual = null; _frameContentVisual?.Dispose(); _frameContentVisual = null; _nextVisualContent?.Dispose(); _nextVisualContent = null; _shadow?.Dispose(); _shadow = null; _layerEffectBrush?.Dispose(); _layerEffectBrush = null; _imageOptions = null; _zoomInAnimationGroup?.Dispose(); _zoomInAnimationGroup = null; _fadeOutAnimation?.Dispose(); _fadeOutAnimation = null; _fadeInAnimation?.Dispose(); _fadeInAnimation = null; _colorAnimation?.Dispose(); _colorAnimation = null; _alignXAnimation?.Dispose(); _alignXAnimation = null; _alignYAnimation?.Dispose(); _alignYAnimation = null; _offsetAnimation?.Dispose(); _offsetAnimation = null; _scaleAnimation?.Dispose(); _scaleAnimation = null; // Dispose the generator at the end to allow the // dependant composition objects to unsubscribe from // generator events _generator?.Dispose(); _generator = null; }