Created
October 2, 2016 12:33
-
-
Save rootasjey/ca502f073a7138c9a4a850fd8eb20ae4 to your computer and use it in GitHub Desktop.
Add and apply a GaussianBlur effect on a image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Install win2D (nuget package) | |
// ParallaxImage is an Image Control in my Page.xaml | |
// ParallaxCanvas is a Canvas Control on my Page.xaml | |
// ParallaxCanvas contains ParallaxImage, so ParallaxCanvas is the parent of ParallaxImage | |
Visual _backgroundVisual = ElementCompositionPreview.GetElementVisual(ParallaxImage); | |
Compositor _backgroundCompositor = _backgroundVisual.Compositor; | |
GaussianBlurEffect blurEffect = new GaussianBlurEffect() { | |
Name = "Blur", | |
BlurAmount = 90.0f, // You can place your blur amount here. | |
BorderMode = EffectBorderMode.Hard, | |
Optimization = EffectOptimization.Balanced, | |
Source = new CompositionEffectSourceParameter("Backdrop") | |
}; | |
var effectFactory = _backgroundCompositor.CreateEffectFactory(blurEffect, new[] { "Blur.BlurAmount" }); | |
var effectBrush = effectFactory.CreateBrush(); | |
var destinationBrush = _backgroundCompositor.CreateBackdropBrush(); | |
effectBrush.SetSourceParameter("Backdrop", destinationBrush); | |
var blurSprite = _backgroundCompositor.CreateSpriteVisual(); | |
blurSprite.Size = new Vector2((float)ParallaxCanvas.ActualWidth, (float)ParallaxCanvas.ActualHeight); | |
blurSprite.Brush = effectBrush; | |
ElementCompositionPreview.SetElementChildVisual(ParallaxCanvas, blurSprite); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment