private async void Button_Click(object sender, RoutedEventArgs e) { using (var stream = await Root.RenderToRandomAccessStream()) { var device = new CanvasDevice(); var bitmap = await CanvasBitmap.LoadAsync(device, stream); var renderer = new CanvasRenderTarget(device, bitmap.SizeInPixels.Width, bitmap.SizeInPixels.Height, bitmap.Dpi); using (var ds = renderer.CreateDrawingSession()) { var blur = new GaussianBlurEffect(); blur.BlurAmount = 5.0f; blur.Source = bitmap; ds.DrawImage(blur); } stream.Seek(0); await renderer.SaveAsync(stream, CanvasBitmapFileFormat.Png); BitmapImage image = new BitmapImage(); image.SetSource(stream); Blured.Source = image; } }
private void AttachBlurAnimation() { GaussianBlurEffect blurEffect = new GaussianBlurEffect() { Name = "Blur", BlurAmount = 0.0f, BorderMode = EffectBorderMode.Hard, Optimization = EffectOptimization.Speed, Source = new CompositionEffectSourceParameter("Backdrop") }; var effectFactory = _compositor.CreateEffectFactory(blurEffect, new[] { "Blur.BlurAmount" }); var effectBrush = effectFactory.CreateBrush(); var destinationBrush = _compositor.CreateBackdropBrush(); effectBrush.SetSourceParameter("Backdrop", destinationBrush); var blurSprite = _compositor.CreateSpriteVisual(); blurSprite.Size = new Vector2((float)BackgroundImage.ActualWidth, (float)BackgroundImage.ActualHeight); blurSprite.Brush = effectBrush; ElementCompositionPreview.SetElementChildVisual(BackgroundImage, blurSprite); ExpressionAnimation backgroundBlurAnimation = _compositor.CreateExpressionAnimation( "Clamp(-scroller.Translation.Y / 10,0,100)"); backgroundBlurAnimation.SetReferenceParameter("scroller", _peopleScrollViewerPropertySet); blurSprite.Brush.Properties.StartAnimation("Blur.BlurAmount", backgroundBlurAnimation); }
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); }
private void InitializeBlur(UIElement element) { var UIelement = element as Grid; GaussianBlurEffect blurEffect = new GaussianBlurEffect() { Name = "Blur", BlurAmount = 20.0f, BorderMode = EffectBorderMode.Hard, Optimization = EffectOptimization.Speed, Source = new CompositionEffectSourceParameter("Backdrop") }; Visual _backgroundVisual = ElementCompositionPreview.GetElementVisual(element); Compositor _backgroundCompositor = _backgroundVisual.Compositor; var effectBrush = _backgroundCompositor.CreateEffectFactory(blurEffect).CreateBrush(); var destinationBrush = _backgroundCompositor.CreateBackdropBrush(); effectBrush.SetSourceParameter("Backdrop", destinationBrush); //Generate a UIElement visual. var blurSprite = _backgroundCompositor.CreateSpriteVisual(); blurSprite.Size = new Vector2((float)UIelement.ActualWidth, (float)UIelement.ActualHeight); blurSprite.Brush = effectBrush; //Then "inject" it to the XAML. ElementCompositionPreview.SetElementChildVisual(element, blurSprite); }
void CreateBrushes(CanvasAnimatedControl sender, CanvasBitmap bitmapTiger) { var bitmapSize = bitmapTiger.Size; var scale = (radius * 2) / (float)bitmapSize.Height; var backgroundEffect = new Transform2DEffect() { Source = bitmapTiger, TransformMatrix = Matrix3x2.CreateScale(scale, scale) * Matrix3x2.CreateTranslation(center - radius, center - radius) }; backgroundBrush = new CanvasImageBrush(sender, backgroundEffect) { SourceRectangle = new Rect(0, 0, size, size), Opacity = 0.6f }; hueRotationEffect = new HueRotationEffect() { Source = backgroundEffect, Angle = (float)Math.PI * 0.5f }; var foregroundEffect = new GaussianBlurEffect() { Source = hueRotationEffect, BlurAmount = 10 }; foregroundBrush = new CanvasImageBrush(sender, foregroundEffect) { SourceRectangle = new Rect(0, 0, size, size) }; }
private void InitialLoadingCanvas() { Visual hostVisual = ElementCompositionPreview.GetElementVisual(LoadingCanvas1); Compositor compositor = hostVisual.Compositor; GaussianBlurEffect blurEffect = new GaussianBlurEffect() { Name = "Blur", BlurAmount = 5.0f, BorderMode = EffectBorderMode.Hard, Optimization = EffectOptimization.Speed, Source = new CompositionEffectSourceParameter("Backdrop") }; var effectFactory = compositor.CreateEffectFactory(blurEffect, new[] { "Blur.BlurAmount" }); var effectBrush = effectFactory.CreateBrush(); var destinationBrush = compositor.CreateBackdropBrush(); effectBrush.SetSourceParameter("Backdrop", destinationBrush); var blurSprite = compositor.CreateSpriteVisual(); blurSprite.Size = new System.Numerics.Vector2((float)LoadingCanvas1.ActualWidth, (float)LoadingCanvas1.ActualHeight); blurSprite.Brush = effectBrush; ElementCompositionPreview.SetElementChildVisual(LoadingCanvas1, blurSprite); var bindSizeAnimation = compositor.CreateExpressionAnimation("hostVisual.Size"); bindSizeAnimation.SetReferenceParameter("hostVisual", hostVisual); blurSprite.StartAnimation("Size", bindSizeAnimation); }
private void Canvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { // Start drawing session and clear background to white. var session = args.DrawingSession; args.DrawingSession.Clear(Colors.White); // Set the center of the radial gradient as the center of the image. radialBrush.Center = new System.Numerics.Vector2((float)(image.Size.Width / 2.0f), (float)(image.Size.Height / 2.0f)); // Assing gradient radius from slider control. radialBrush.RadiusX = radialBrush.RadiusY = (float)BlurRadius.Value; // Draw unaltered image first. session.DrawImage(image, image.Bounds); // Create a layer, this way all elements drawn will be affected by a transparent mask // which in our case is the radial gradient. using (session.CreateLayer(radialBrush)) { // Create gaussian blur effect. using (var blurEffect = new GaussianBlurEffect()) { // Set image to blur. blurEffect.Source = image; // Set blur amount from slider control. blurEffect.BlurAmount = (float)BlurAmount.Value; // Explicitly set optimization mode to highest quality, since we are using big blur amount values. blurEffect.Optimization = EffectOptimization.Quality; // This prevents the blur effect from wrapping around. blurEffect.BorderMode = EffectBorderMode.Hard; // Draw blurred image on top of the unaltered one. It will be masked by the radial gradient // thus showing a transparent hole in the middle, and properly overlaying the alpha values. session.DrawImage(blurEffect, 0, 0); } } }
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); }
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"); } }
//<SnippetVideoFrameAvailable> private async void mediaPlayer_VideoFrameAvailable(MediaPlayer sender, object args) { CanvasDevice canvasDevice = CanvasDevice.GetSharedDevice(); await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { if (frameServerDest == null) { // FrameServerImage in this example is a XAML image control frameServerDest = new SoftwareBitmap(BitmapPixelFormat.Rgba8, (int)FrameServerImage.Width, (int)FrameServerImage.Height, BitmapAlphaMode.Ignore); } if (canvasImageSource == null) { canvasImageSource = new CanvasImageSource(canvasDevice, (int)FrameServerImage.Width, (int)FrameServerImage.Height, DisplayInformation.GetForCurrentView().LogicalDpi);//96); FrameServerImage.Source = canvasImageSource; } using (CanvasBitmap inputBitmap = CanvasBitmap.CreateFromSoftwareBitmap(canvasDevice, frameServerDest)) using (CanvasDrawingSession ds = canvasImageSource.CreateDrawingSession(Windows.UI.Colors.Black)) { mediaPlayer.CopyFrameToVideoSurface(inputBitmap); var gaussianBlurEffect = new GaussianBlurEffect { Source = inputBitmap, BlurAmount = 5f, Optimization = EffectOptimization.Speed }; ds.DrawImage(gaussianBlurEffect); } }); }
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); }
public PolaroidEffect() { blurFx = new GaussianBlurEffect { Sigma = 0.15f }; vignetteFx = new VignetteEffect(); tintFx = TintEffect.Sepia; mixer = new BitmapMixer { Mixture = 0.5f }; }
private void Initialize() { _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; var frostEffect = new GaussianBlurEffect { BlurAmount = 16.0f, BorderMode = EffectBorderMode.Hard, Source = new CompositionEffectSourceParameter("backdropBrush") }; // Create an instance of the effect and set its source to a CompositionBackdropBrush var effectFactory = _compositor.CreateEffectFactory(frostEffect); var backdropBrush = _compositor.CreateBackdropBrush(); var effectBrush = effectFactory.CreateBrush(); effectBrush.SetSourceParameter("backdropBrush", backdropBrush); // Create a Visual to contain the frosted glass effect _hostVisual = _compositor.CreateSpriteVisual(); _hostVisual.Brush = effectBrush; _hostVisual.Size = new Vector2((float)ActualWidth, (float)ActualHeight); // Add the blur as a child of the host in the visual tree ElementCompositionPreview.SetElementChildVisual(this, _hostVisual); }
private CompositionEffectBrush BuildColoredBlurBrush() { var gaussianBlur = new GaussianBlurEffect { Name = "Blur", Source = new CompositionEffectSourceParameter("source"), BlurAmount = 15.0f, BorderMode = EffectBorderMode.Hard, Optimization = EffectOptimization.Balanced }; var colorEffect = new ColorSourceEffect { Name = "ColorSource2", Color = (Color)App.Current.Resources["KlivaMainColor"] }; var blendEffect = new BlendEffect { Mode = BlendEffectMode.Multiply, Background = gaussianBlur, Foreground = colorEffect }; var factory = m_compositor.CreateEffectFactory(blendEffect); var brush = factory.CreateBrush(); return(brush); }
private CompositionEffectBrush BuildBlurBrush(Compositor c, float blurAmount, Color maskColor) { var blurDesc = new GaussianBlurEffect { Name = "GlassBlur", BlurAmount = blurAmount, BorderMode = EffectBorderMode.Hard, Optimization = EffectOptimization.Balanced, Source = new CompositionEffectSourceParameter("Source") }; var colorDesc = new ColorSourceEffect { Name = "GlassColor", Color = maskColor, }; var blendEffectDesc = new BlendEffect { Mode = BlendEffectMode.Multiply, Background = blurDesc, Foreground = colorDesc, }; var blurBrush = c.CreateEffectFactory(blendEffectDesc, new[] { "GlassBlur.BlurAmount", "GlassColor.Color" }).CreateBrush(); blurBrush.SetSourceParameter("Source", c.CreateBackdropBrush()); return blurBrush; }
protected override void OnConnected() { // Delay creating composition resources until they're required. if (CompositionBrush == null) { var backdrop = Window.Current.Compositor.CreateBackdropBrush(); // Use a Win2D blur affect applied to a CompositionBackdropBrush. var graphicsEffect = new GaussianBlurEffect { Name = "Blur", BlurAmount = (float)this.BlurAmount, Source = new CompositionEffectSourceParameter("backdrop") }; var effectFactory = Window.Current.Compositor.CreateEffectFactory(graphicsEffect, new[] { "Blur.BlurAmount" }); var effectBrush = effectFactory.CreateBrush(); effectBrush.SetSourceParameter("backdrop", backdrop); CompositionBrush = effectBrush; if (BlurAmountExpression != null) { CompositionBrush.StartAnimation("Blur.BlurAmount", BlurAmountExpression); } } }
private CompositionDrawingSurface SampleImageColor(CanvasBitmap bitmap, CompositionGraphicsDevice device, Size sizeTarget) { // Extract the color to tint the blur with Color predominantColor = ExtractPredominantColor(bitmap.GetPixelColors(), bitmap.Size); Size sizeSource = bitmap.Size; if (sizeTarget.IsEmpty) { sizeTarget = sizeSource; } // Create a heavily blurred version of the image GaussianBlurEffect blurEffect = new GaussianBlurEffect() { Source = bitmap, BlurAmount = 20.0f }; CompositionDrawingSurface surface = device.CreateDrawingSurface(sizeTarget, DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied); using (var ds = CanvasComposition.CreateDrawingSession(surface)) { Rect destination = new Rect(0, 0, sizeTarget.Width, sizeTarget.Height); ds.FillRectangle(destination, predominantColor); ds.DrawImage(blurEffect, destination, new Rect(0, 0, sizeSource.Width, sizeSource.Height), .6f); } return(surface); }
public void EffectExceptionMessages() { var effect = new GaussianBlurEffect(); using (var device = new CanvasDevice()) using (var renderTarget = new CanvasRenderTarget(device, 1, 1, 96)) using (var drawingSession = renderTarget.CreateDrawingSession()) { // Null source. try { drawingSession.DrawImage(effect); Assert.Fail("should throw"); } catch (NullReferenceException e) { VerifyExceptionMessage("Effect source #0 is null.", e.Message); } // Invalid source type. effect.Source = new NotACanvasImage(); try { drawingSession.DrawImage(effect); Assert.Fail("should throw"); } catch (InvalidCastException e) { VerifyExceptionMessage("Effect source #0 is an unsupported type. To draw an effect using Win2D, all its sources must be Win2D ICanvasImage objects.", e.Message); } } }
CompositionDrawingSurface ApplyBlurEffect(CanvasBitmap bitmap, Windows.UI.Composition.CompositionGraphicsDevice device, Size sizeTarget) { GaussianBlurEffect blurEffect = new GaussianBlurEffect() { Source = bitmap, BlurAmount = 20.0f, BorderMode = EffectBorderMode.Hard, }; float fDownsample = .3f; Size sizeSource = bitmap.Size; if (sizeTarget == Size.Empty) { sizeTarget = sizeSource; } sizeTarget = new Size(sizeTarget.Width * fDownsample, sizeTarget.Height * fDownsample); CompositionDrawingSurface blurSurface = device.CreateDrawingSurface(sizeTarget, DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied); using (var ds = CanvasComposition.CreateDrawingSession(blurSurface)) { Rect destination = new Rect(0, 0, sizeTarget.Width, sizeTarget.Height); ds.Clear(Windows.UI.Color.FromArgb(255, 255, 255, 255)); ds.DrawImage(blurEffect, destination, new Rect(0, 0, sizeSource.Width, sizeSource.Height)); } return(blurSurface); }
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 BlurComponent(Device graphics, int size) { _graphics = graphics; Dims = size; Format = Format.A8R8G8B8; _sampleOffsetsHoriz = new Vector4D[SampleCount]; _sampleOffsetsVert = new Vector4D[SampleCount]; _sampleWeightsHoriz = new float[SampleCount]; _sampleWeightsVert = new float[SampleCount]; int width = Dims - 5; int height = Dims - 5; SetBlurEffectParameters(1.0f / width, 0, ref _sampleOffsetsHoriz, ref _sampleWeightsHoriz); SetBlurEffectParameters(0, 1.0f / height, ref _sampleOffsetsVert, ref _sampleWeightsVert); _effect = new GaussianBlurEffect(_graphics); OutputTexture = new Texture(_graphics, Dims, Dims, 1, Usage.RenderTarget, Format, Pool.Default); _intermediateTexture = new Texture(_graphics, Dims, Dims, 1, Usage.RenderTarget, Format, Pool.Default); _sprite = new Sprite(_graphics); }
private CompositionEffectBrush CreateBlurEffect(Compositor compositor) { var blendEffect0 = new ArithmeticCompositeEffect() { MultiplyAmount = 0, Source1Amount = _backdropFactor, Source2Amount = _tintColorFactor, Source1 = new CompositionEffectSourceParameter(SOURCE_KEY), Source2 = new ColorSourceEffect() { Color = _tintColor } }; var effect = new GaussianBlurEffect() { BlurAmount = _blurAmount, BorderMode = EffectBorderMode.Soft, Source = blendEffect0 }; var effectFactory = compositor.CreateEffectFactory(effect); var effectBrush = effectFactory.CreateBrush(); return(effectBrush); }
public static async Task <BitmapImage> GetBluredImage(string url) { BitmapImage image = new BitmapImage(); CanvasDevice device = CanvasDevice.GetSharedDevice(); CanvasRenderTarget offscreen = new CanvasRenderTarget(device, 400, 150, 96); try { var cbi = await CanvasBitmap.LoadAsync(device, new Uri(url)); using (var ds = offscreen.CreateDrawingSession()) { var blur = new GaussianBlurEffect(); blur.BlurAmount = 15f; blur.Source = cbi; ds.DrawImage(blur); } using (var stream = new InMemoryRandomAccessStream()) { stream.Seek(0); await offscreen.SaveAsync(stream, CanvasBitmapFileFormat.Png); image.SetSource(stream); } } catch { } return(image); }
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 OnDraw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args) { var textDisplay = GenerateTextDisplay(sender, (float)sender.Size.Width, (float)sender.Size.Height); var blurEffect = new GaussianBlurEffect() { Source = textDisplay, BlurAmount = 10 }; textOpacityBrush.StartPoint = blurOpacityBrush.StartPoint = new Vector2(0, 0); textOpacityBrush.EndPoint = blurOpacityBrush.EndPoint = new Vector2(0, (float)sender.Size.Height); var ds = args.DrawingSession; using (ds.CreateLayer(blurOpacityBrush)) { ds.DrawImage(blurEffect); } using (ds.CreateLayer(textOpacityBrush)) { ds.DrawImage(textDisplay); } }
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); }
/// <summary> /// Initializes the Composition Brush. /// </summary> protected override void OnConnected() { // Delay creating composition resources until they're required. if (CompositionBrush == null) { // Abort if effects aren't supported. if (!CompositionCapabilities.GetForCurrentView().AreEffectsSupported()) { return; } var backdrop = Window.Current.Compositor.CreateBackdropBrush(); // Use a Win2D blur affect applied to a CompositionBackdropBrush. var graphicsEffect = new GaussianBlurEffect { Name = "Blur", BlurAmount = (float)Amount, Source = new CompositionEffectSourceParameter("backdrop") }; var effectFactory = Window.Current.Compositor.CreateEffectFactory(graphicsEffect, new[] { "Blur.BlurAmount" }); var effectBrush = effectFactory.CreateBrush(); effectBrush.SetSourceParameter("backdrop", backdrop); CompositionBrush = effectBrush; } }
private static CompositionBrush CreateBlurBrush() { if (_blurBrush != null) { return(_blurBrush); } var blurEffect = new GaussianBlurEffect { Name = "Blur", BlurAmount = 15.0f, BorderMode = EffectBorderMode.Hard, Optimization = EffectOptimization.Balanced, Source = new CompositionEffectSourceParameter("source") }; var blendEffect = new BlendEffect { Background = blurEffect, Foreground = new ColorSourceEffect { Name = "Color", Color = Color.FromArgb(64, 0, 0, 0) }, Mode = BlendEffectMode.SoftLight }; var blurEffectFactory = _compositor.CreateEffectFactory(blendEffect); var blurBrush = blurEffectFactory.CreateBrush(); var backdropBrush = _compositor.CreateBackdropBrush(); blurBrush.SetSourceParameter("source", backdropBrush); _blurBrush = blurBrush; return(_blurBrush); }
private CompositionEffectBrush BuildBlurBrush() { var blurEffect = new GaussianBlurEffect { Name = "Blur", BlurAmount = 0.0f, BorderMode = EffectBorderMode.Hard, Optimization = EffectOptimization.Balanced, Source = new CompositionEffectSourceParameter("Source") }; var blendEffect = new BlendEffect { Background = blurEffect, Foreground = new ColorSourceEffect { Name = "Color", Color = Color.FromArgb(90, 255, 255, 255) }, Mode = BlendEffectMode.SoftLight }; var saturationEffect = new SaturationEffect { Name = "Saturation", Source = blendEffect, Saturation = 1.75f }; var factory = _compositor.CreateEffectFactory( saturationEffect, new[] { "Blur.BlurAmount", "Color.Color", "Saturation.Saturation" }); return(factory.CreateBrush()); }
private CompositionEffectBrush BuildBlurBrush() { GaussianBlurEffect blurEffect = new GaussianBlurEffect() { Name = "Blur", BlurAmount = 0.0f, BorderMode = EffectBorderMode.Hard, Optimization = EffectOptimization.Balanced }; blurEffect.Source = new CompositionEffectSourceParameter("source"); BlendEffect effect = new BlendEffect { Foreground = new ColorSourceEffect { Name = "Color", Color = Colors.Transparent }, Background = blurEffect, Mode = BlendEffectMode.Multiply }; var factory = Compositor.CreateEffectFactory( effect, new[] { "Blur.BlurAmount", "Color.Color" } ); return(factory.CreateBrush()); }
/// <summary> /// 毛玻璃效果 /// </summary> /// <param name="glassHost"></param> private void initGlass(UIElement glassHost) { Visual hostVisual = ElementCompositionPreview.GetElementVisual(glassHost); Compositor compositor = hostVisual.Compositor; var glassEffect = new GaussianBlurEffect { BlurAmount = 10f, BorderMode = EffectBorderMode.Hard, Source = new ArithmeticCompositeEffect { MultiplyAmount = 0, Source1Amount = 0.7f, Source2Amount = 0.3f, Source1 = new CompositionEffectSourceParameter("backdropBrush"), Source2 = new ColorSourceEffect { Color = Color.FromArgb(255, 245, 245, 245) } } }; var effectFactory = compositor.CreateEffectFactory(glassEffect); var backdropBrush = compositor.CreateHostBackdropBrush(); var effectBrush = effectFactory.CreateBrush(); effectBrush.SetSourceParameter("backdropBrush", backdropBrush); var glassVisual = compositor.CreateSpriteVisual(); glassVisual.Brush = effectBrush; ElementCompositionPreview.SetElementChildVisual(glassHost, glassVisual); var bindSizeAnimation = compositor.CreateExpressionAnimation("hostVisual.Size"); bindSizeAnimation.SetReferenceParameter("hostVisual", hostVisual); glassVisual.StartAnimation("Size", bindSizeAnimation); }
private void InitializeEffects() { saturationEffect = new SaturationEffect() { Name = "SaturationEffect", Saturation = item.Saturation, Source = new CompositionEffectSourceParameter("Backdrop") }; contrastEffect = new ContrastEffect() { Name = "ContrastEffect", Contrast = item.Contrast, Source = saturationEffect }; exposureEffect = new ExposureEffect() { Name = "ExposureEffect", Source = contrastEffect, Exposure = item.Exposure, }; temperatureAndTintEffect = new TemperatureAndTintEffect() { Name = "TemperatureAndTintEffect", Source = exposureEffect, Temperature = item.Temperature, Tint = item.Tint }; graphicsEffect = new GaussianBlurEffect() { Name = "Blur", Source = temperatureAndTintEffect, BlurAmount = item.Blur, BorderMode = EffectBorderMode.Hard, }; }
private async Task CreateResourcesAsync(CanvasControl sender) { m_BackgroundImage = await CanvasBitmap.LoadAsync(sender.Device, new Uri("ms-appx:///Assets/setup_bg.jpg")); //m_BackgroundImageInitialAlpha = await CanvasBitmap.LoadAsync(sender.Device, new Uri("ms-appx:///Assets/nuki_initial.png")); var blured = new GaussianBlurEffect() { Source = m_BackgroundImage, BlurAmount = 10.0f, }; m_BluredBackground = new BlendEffect() { Background = blured, Foreground = new ColorSourceEffect() { Color = Windows.UI.Color.FromArgb(25, 0, 0, 0) }, Mode = BlendEffectMode.Darken }; m_BlendedBackground = new BlendEffect() { Background = blured, Foreground = new ColorSourceEffect() { Color = Windows.UI.Color.FromArgb(100, 0, 0, 0) }, Mode = BlendEffectMode.Darken }; m_ImageStatus = ImageLoadStatus.Fading; sender.Invalidate(); }
public GlowEffect() { EffectData = new GlowData (); blurEffect = new GaussianBlurEffect (); contrastEffect = new BrightnessContrastEffect (); screenBlendOp = new UserBlendOps.ScreenBlendOp (); }
public void Dispose() { _cl?.Dispose(); _cl = null; morphology?.Dispose(); morphology = null; blur?.Dispose(); blur = null; }
public SoftenPortraitEffect () { EffectData = new SoftenPortraitData (); blurEffect = new GaussianBlurEffect (); bacAdjustment = new BrightnessContrastEffect (); desaturateOp = new UnaryPixelOps.Desaturate (); overlayOp = new UserBlendOps.OverlayBlendOp (); }
public PencilSketchEffect() { EffectData = new PencilSketchData (); blurEffect = new GaussianBlurEffect (); desaturateOp = new UnaryPixelOps.Desaturate (); invertEffect = new InvertColorsEffect (); bacAdjustment = new BrightnessContrastEffect (); colorDodgeOp = new UserBlendOps.ColorDodgeBlendOp (); }
private void Canvas_Draw(CanvasControl sender, CanvasDrawEventArgs args) { GaussianBlurEffect effect = new GaussianBlurEffect() { Source = _bitmap, BlurAmount = 5, BorderMode = EffectBorderMode.Hard }; args.DrawingSession.DrawImage(effect); }
/// <summary> /// Applys a blur to a UI element /// </summary> /// <param name="sourceElement">UIElement to blur, generally an Image control, but can be anything</param> /// <param name="blurAmount">Level of blur to apply</param> /// <returns>Blurred UIElement as BitmapImage</returns> public static async Task<BitmapImage> BlurElementAsync(this UIElement sourceElement, float blurAmount = 2.0f) { if (sourceElement == null) return null; var rtb = new RenderTargetBitmap(); await rtb.RenderAsync(sourceElement); var buffer = await rtb.GetPixelsAsync(); var array = buffer.ToArray(); var displayInformation = DisplayInformation.GetForCurrentView(); using (var stream = new InMemoryRandomAccessStream()) { var pngEncoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream); pngEncoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied, (uint) rtb.PixelWidth, (uint) rtb.PixelHeight, displayInformation.RawDpiX, displayInformation.RawDpiY, array); await pngEncoder.FlushAsync(); stream.Seek(0); var canvasDevice = new CanvasDevice(); var bitmap = await CanvasBitmap.LoadAsync(canvasDevice, stream); var renderer = new CanvasRenderTarget(canvasDevice, bitmap.SizeInPixels.Width, bitmap.SizeInPixels.Height, bitmap.Dpi); using (var ds = renderer.CreateDrawingSession()) { var blur = new GaussianBlurEffect { BlurAmount = blurAmount, Source = bitmap }; ds.DrawImage(blur); } stream.Seek(0); await renderer.SaveAsync(stream, CanvasBitmapFileFormat.Png); var image = new BitmapImage(); await image.SetSourceAsync(stream); return image; } }
public void ProcessFrame(ProcessVideoFrameContext context) { using (CanvasBitmap inputBitmap = CanvasBitmap.CreateFromDirect3D11Surface(canvasDevice, context.InputFrame.Direct3DSurface)) using (CanvasRenderTarget renderTarget = CanvasRenderTarget.CreateFromDirect3D11Surface(canvasDevice, context.OutputFrame.Direct3DSurface)) using (CanvasDrawingSession ds = renderTarget.CreateDrawingSession()) { var gaussianBlurEffect = new GaussianBlurEffect { Source = inputBitmap, BlurAmount = (float)BlurAmount, Optimization = EffectOptimization.Speed }; ds.DrawImage(gaussianBlurEffect); } }
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); }
public Renderer(CoreWindow window) { this.window = window; window.PointerPressed += window_PointerPressed; window.PointerMoved += window_PointerMoved; window.PointerReleased += window_PointerReleased; device = new CanvasDevice(); swapChainManager = new SwapChainManager(window, device); var effect = new GaussianBlurEffect() { BlurAmount = 5, Source = inputEffect }; outputEffect = new Transform2DEffect() { Source = effect }; imageBrush = new CanvasImageBrush(device); imageBrush.Opacity = 0.99f; }
void InitializeBloomFilter() { BloomEnabled = true; // A bloom filter makes graphics appear to be bright and glowing by adding blur around only // the brightest parts of the image. This approximates the look of HDR (high dynamic range) // rendering, in which the color of the brightest light sources spills over onto surrounding // pixels. // // Many different visual styles can be achieved by adjusting these settings: // // Intensity = how much bloom is added // 0 = none // // Threshold = how bright does a pixel have to be in order for it to bloom // 0 = the entire image blooms equally // // Blur = how much the glow spreads sideways around bright areas BloomIntensity = 200; BloomThreshold = 80; BloomBlur = 48; // Before drawing, properties of these effects will be adjusted to match the // current settings (see ApplyBloomFilter), and an input image connected to // extractBrightAreas.Source and bloomResult.Background (see DemandCreateBloomRenderTarget). // Step 1: use a transfer effect to extract only pixels brighter than the threshold. extractBrightAreas = new LinearTransferEffect { ClampOutput = true, }; // Step 2: blur these bright pixels. blurBrightAreas = new GaussianBlurEffect { Source = extractBrightAreas, }; // Step 3: adjust how much bloom is wanted. adjustBloomIntensity = new LinearTransferEffect { Source = blurBrightAreas, }; // Step 4: blend the bloom over the top of the original image. bloomResult = new BlendEffect { Foreground = adjustBloomIntensity, Mode = BlendEffectMode.Screen, }; }
void DrawStuff(CanvasDrawingSession ds) { int horizontalLimit = (int)m_canvasControl.ActualWidth; int verticalLimit = (int)m_canvasControl.ActualHeight; const float thickStrokeWidth = 80.0f; DrawnContentType drawnContentType = (DrawnContentType)m_drawnContentTypeCombo.SelectedValue; ds.Clear(NextRandomColor()); Rect rect; Vector2 point; float radiusX; float radiusY; switch (drawnContentType) { case DrawnContentType.Clear_Only: break; case DrawnContentType.Bitmap: if (m_bitmap_tiger != null) { ds.DrawImage(m_bitmap_tiger, NextRandomPoint(horizontalLimit, verticalLimit).ToVector2()); } else { DrawNoBitmapErrorMessage(ds, horizontalLimit / 2, verticalLimit / 2); } break; case DrawnContentType.Effect_Blur: if (m_bitmap_tiger != null) { GaussianBlurEffect blurEffect = new GaussianBlurEffect(); blurEffect.StandardDeviation = 2.0f; blurEffect.Source = m_bitmap_tiger; ds.DrawImage(blurEffect, NextRandomPoint(horizontalLimit, verticalLimit).ToVector2()); } else { DrawNoBitmapErrorMessage(ds, horizontalLimit / 2, verticalLimit / 2); } break; case DrawnContentType.Line_Thin: ds.DrawLine( NextRandomPoint(horizontalLimit, verticalLimit).ToVector2(), NextRandomPoint(horizontalLimit, verticalLimit).ToVector2(), NextRandomColor()); break; case DrawnContentType.Line_Thick: ds.DrawLine( NextRandomPoint(horizontalLimit, verticalLimit).ToVector2(), NextRandomPoint(horizontalLimit, verticalLimit).ToVector2(), NextRandomColor(), thickStrokeWidth); break; case DrawnContentType.Rectangle_Thin: ds.DrawRectangle( NextRandomRect(horizontalLimit, verticalLimit), NextRandomColor()); break; case DrawnContentType.Rectangle_Thick: ds.DrawRectangle( NextRandomRect(horizontalLimit, verticalLimit), NextRandomColor(), thickStrokeWidth); break; case DrawnContentType.Rectangle_Filled: ds.FillRectangle( NextRandomRect(horizontalLimit, verticalLimit), NextRandomColor()); break; case DrawnContentType.RoundedRectangle_Thin: NextRandomRoundedRect(horizontalLimit, verticalLimit, out rect, out radiusX, out radiusY); ds.DrawRoundedRectangle( rect, radiusX, radiusY, NextRandomColor()); break; case DrawnContentType.RoundedRectangle_Thick: NextRandomRoundedRect(horizontalLimit, verticalLimit, out rect, out radiusX, out radiusY); ds.DrawRoundedRectangle( rect, radiusX, radiusY, NextRandomColor(), thickStrokeWidth); break; case DrawnContentType.Ellipse_Thin: NextRandomEllipse(horizontalLimit, verticalLimit, out point, out radiusX, out radiusY); ds.DrawEllipse( point, radiusX, radiusY, NextRandomColor()); break; case DrawnContentType.Ellipse_Thick: NextRandomEllipse(horizontalLimit, verticalLimit, out point, out radiusX, out radiusY); ds.DrawEllipse( point, radiusX, radiusY, NextRandomColor(), thickStrokeWidth); break; case DrawnContentType.Ellipse_Fill: NextRandomEllipse(horizontalLimit, verticalLimit, out point, out radiusX, out radiusY); ds.FillEllipse( point, radiusX, radiusY, NextRandomColor()); break; case DrawnContentType.Circle_Fill: ds.FillCircle( NextRandomPoint(horizontalLimit, verticalLimit).ToVector2(), 100, NextRandomColor()); break; case DrawnContentType.Dashed_Lines: DrawDashedLines(ds, NextRandomColor(), horizontalLimit, verticalLimit); break; case DrawnContentType.Text: var p = NextRandomPoint(horizontalLimit, verticalLimit); var x = (float)p.X; var y = (float)p.Y; var color = NextRandomColor(); ds.DrawLine(new Vector2(x, 0), new Vector2(x, verticalLimit), color); ds.DrawLine(new Vector2(0, y), new Vector2(horizontalLimit, y), color); ds.DrawText( "Centered", p.ToVector2(), color, new CanvasTextFormat() { FontSize = 18, VerticalAlignment = CanvasVerticalAlignment.Center, ParagraphAlignment = ParagraphAlignment.Center }); var r = NextRandomRect(horizontalLimit, verticalLimit); ds.DrawRectangle(r, color); ds.DrawText( m_quiteLongText, r, NextRandomColor(), new CanvasTextFormat() { FontFamily = "Comic Sans MS", FontSize = 18, ParagraphAlignment = ParagraphAlignment.Justify, Options = CanvasDrawTextOptions.Clip }); break; case DrawnContentType.ImageBrush: if (m_bitmap_tiger != null) { m_imageBrush.Image = m_bitmap_tiger; m_imageBrush.ExtendX = (CanvasEdgeBehavior)(m_random.Next(3)); m_imageBrush.ExtendY = (CanvasEdgeBehavior)(m_random.Next(3)); ds.FillRectangle(new Rect(0, 0, horizontalLimit, verticalLimit), m_imageBrush); } else DrawNoBitmapErrorMessage(ds, horizontalLimit / 2, verticalLimit / 2); break; case DrawnContentType.Test_Scene0_Default: GeometryTestScene0.DrawGeometryTestScene(ds, TestSceneRenderingType.Default); break; case DrawnContentType.Test_Scene0_Wireframe: GeometryTestScene0.DrawGeometryTestScene(ds, TestSceneRenderingType.Wireframe); break; case DrawnContentType.Test_Scene1_Default: GeometryTestScene1.DrawGeometryTestScene(ds, TestSceneRenderingType.Default); break; case DrawnContentType.Test_Scene1_Randomized: GeometryTestScene1.DrawGeometryTestScene(ds, TestSceneRenderingType.Randomized); break; case DrawnContentType.Test_Scene1_Wireframe: GeometryTestScene1.DrawGeometryTestScene(ds, TestSceneRenderingType.Wireframe); break; default: System.Diagnostics.Debug.Assert(false); // Unexpected break; } }
private CompositionEffectBrush BuildBlurBrush() { GaussianBlurEffect blurEffect = new GaussianBlurEffect() { Name = "Blur", BlurAmount = 0.0f, BorderMode = EffectBorderMode.Hard, Optimization = EffectOptimization.Balanced, Source = new CompositionEffectSourceParameter("source"), }; BlendEffect blendEffect = new BlendEffect { Background = blurEffect, Foreground = new ColorSourceEffect { Name = "Color", Color = Color.FromArgb(64, 255, 255, 255) }, Mode = BlendEffectMode.SoftLight }; SaturationEffect saturationEffect = new SaturationEffect { Source = blendEffect, Saturation = 1.75f, }; BlendEffect finalEffect = new BlendEffect { Foreground = new CompositionEffectSourceParameter("NoiseImage"), Background = saturationEffect, Mode = BlendEffectMode.Screen, }; var factory = Compositor.CreateEffectFactory( finalEffect, new[] { "Blur.BlurAmount", "Color.Color" } ); CompositionEffectBrush brush = factory.CreateBrush(); brush.SetSourceParameter("NoiseImage", m_noiseBrush); return brush; }
private ICanvasImage CreateGaussianBlur() { var blurEffect = new GaussianBlurEffect { Source = bitmapTiger }; // Animation changes the blur amount. animationFunction = elapsedTime => { blurEffect.BlurAmount = ((float)Math.Sin(elapsedTime * 3) + 1) * 6; }; return blurEffect; }
private ICanvasImage AddSoftEdgedCrop(ICanvasImage effect) { var size = bitmapTiger.Size; var softEdge = new GaussianBlurEffect { Source = new CropEffect { Source = new ColorSourceEffect { Color = Colors.Black }, SourceRectangle = new Rect(-size.Width / 2, -size.Height / 2, size.Width * 2, size.Height * 2) }, BlurAmount = 32 }; return new CompositeEffect { Sources = { softEdge, effect }, Mode = CanvasComposite.SourceIn }; }
//Creates textures of different sizes public void CreateParticleBitmaps(bool blur = false) { SetColors(baseColor); particleBitmaps = new CanvasRenderTarget[sizes]; int i = -1; var nextRadius = 0; var nextSize =0; var transparent = Color.FromArgb(0, 0, 0, 0); float viewportsize = 100; //Here is the trick, if this value is too small appears the displacement and the original image for (int r = 1; r < sizes + 1; r += 1) { nextRadius = (r * minRadius); nextSize = nextRadius * 2; CanvasRenderTarget canvas = new CanvasRenderTarget(device, viewportsize, viewportsize, parent.Dpi); var center = new Vector2((viewportsize - nextRadius) / 2); //The following is like a 'drawing graph', the output of the first is the input of the second one; using (CanvasDrawingSession targetSession = canvas.CreateDrawingSession()) { targetSession.Clear(transparent); targetSession.FillCircle(center, nextRadius, outerColor); targetSession.FillCircle(center, nextRadius - 6, innerColor); } if (!blur) { particleBitmaps[++i] = canvas; } else //Add blur just one time { var blurEffect = new GaussianBlurEffect() { BlurAmount = 2f }; CanvasRenderTarget blurredcanvas = new CanvasRenderTarget(device, viewportsize, viewportsize, parent.Dpi); blurEffect.Source = canvas; using (CanvasDrawingSession targetSession = blurredcanvas.CreateDrawingSession()) { targetSession.Clear(transparent); targetSession.DrawImage(blurEffect); } particleBitmaps[++i] = blurredcanvas; } } }
/// <summary> /// Creates a CompositionEffectFactory that creates GaussianBlurEffects. /// </summary> /// <returns>CompositionEffectFactory</returns> private CompositionEffectFactory CreateBlurEffectFactory() { var effectDefinition = new GaussianBlurEffect() { Name = "Blur", BlurAmount = 0.0f, BorderMode = EffectBorderMode.Hard, Source = new CompositionEffectSourceParameter("Video") }; return _compositor.CreateEffectFactory(effectDefinition, new string[] { "Blur.BlurAmount" }); }
public void ProcessFrame(ProcessVideoFrameContext context) { var inputSurface = context.InputFrame.Direct3DSurface; var outputSurface = context.OutputFrame.Direct3DSurface; using (var inputBitmap = CanvasBitmap.CreateFromDirect3D11Surface(canvasDevice, inputSurface)) using (var renderTarget = CanvasRenderTarget.CreateFromDirect3D11Surface(canvasDevice, outputSurface)) using (var ds = renderTarget.CreateDrawingSession()) using (var brush = new CanvasImageBrush(canvasDevice, inputBitmap)) using (var textCommandList = new CanvasCommandList(canvasDevice)) { using (var clds = textCommandList.CreateDrawingSession()) { clds.DrawText( "Win2D\nMediaClip", (float)inputBitmap.Size.Width / 2, (float)inputBitmap.Size.Height / 2, brush, new CanvasTextFormat() { FontSize = (float)inputBitmap.Size.Width / 5, FontWeight = new FontWeight() { Weight = 999 }, HorizontalAlignment = CanvasHorizontalAlignment.Center, VerticalAlignment = CanvasVerticalAlignment.Center }); } var background = new GaussianBlurEffect() { BlurAmount = 10, BorderMode = EffectBorderMode.Hard, Source = new BrightnessEffect() { BlackPoint = new Vector2(0.5f, 0.7f), Source = new SaturationEffect() { Saturation = 0, Source = inputBitmap } } }; var shadow = new ShadowEffect() { Source = textCommandList, BlurAmount = 10 }; var composite = new CompositeEffect() { Sources = { background, shadow, textCommandList } }; ds.DrawImage(composite); } }
void Canvas_Draw(CanvasControl sender, CanvasDrawEventArgs args) { using (var session = args.DrawingSession) { var blur = new GaussianBlurEffect { BlurAmount = 50.0f, // increase this to make it more blurry or vise versa. //Optimization = EffectOptimization.Balanced, // default value //BorderMode = EffectBorderMode.Soft // default value Source = _bitmap }; session.DrawImage(blur, new Rect(0, 0, sender.ActualWidth, sender.ActualHeight), new Rect(0, 0, _bitmap.SizeInPixels.Width, _bitmap.SizeInPixels.Height), 0.9f); } }
private void CreateEffectAnimations() { // Create saturation effect var saturationEffect = new SaturationEffect { Name = "saturationEffect", Saturation = 1f, Source = new CompositionEffectSourceParameter("foregroundLayerVisual"), }; var saturationFactory = _compositor.CreateEffectFactory(saturationEffect, new[] { "saturationEffect.Saturation" }); _saturationBrush = saturationFactory.CreateBrush(); // Apply animatable saturation effect to foreground visuals _foregroundLayerVisual.Effect = _saturationBrush; // Create blur effect var blurEffect = new GaussianBlurEffect { Name = "blurEffect", BlurAmount = 0f, BorderMode = EffectBorderMode.Hard, Source = new CompositionEffectSourceParameter("backgroundLayerVisual"), }; var blurFactory = _compositor.CreateEffectFactory(blurEffect, new[] { "blurEffect.BlurAmount" }); _blurBrush = blurFactory.CreateBrush(); // Apply animatable saturation effect to foreground visuals _backgroundLayerVisual.Effect = _blurBrush; // Initialize effect animations var lin = _compositor.CreateLinearEasingFunction(); _saturationAnimation = _compositor.CreateScalarKeyFrameAnimation(); _saturationAnimation.InsertKeyFrame(0, 1f, lin); _saturationAnimation.InsertKeyFrame(1, 0f, lin); _saturationAnimation.Duration = _duration; _blurAnimation = _compositor.CreateScalarKeyFrameAnimation(); _blurAnimation.InsertKeyFrame(0, 0f, lin); _blurAnimation.InsertKeyFrame(1, 20f, lin); _blurAnimation.Duration = _duration; }
private async void PlayBackImage_ImageOpened(IRandomAccessStream stream) { if (CurrentSong != null) { { var device = new CanvasDevice(); var bitmap = await CanvasBitmap.LoadAsync(device, stream); var renderer = new CanvasRenderTarget(device, bitmap.SizeInPixels.Width, bitmap.SizeInPixels.Height, bitmap.Dpi); using (var ds = renderer.CreateDrawingSession()) { var blur = new GaussianBlurEffect { Source = bitmap }; blur.BlurAmount = 16.0f; blur.BorderMode = EffectBorderMode.Hard; ds.DrawImage(blur); } stream.Seek(0); await renderer.SaveAsync(stream, CanvasBitmapFileFormat.Png); stream.Seek(0); BitmapImage image = new BitmapImage(); image.SetSource(stream); BackgroundBlur.Source = image; renderer = null; bitmap = null; device = null; GC.Collect(); } } }
static void DrawTile(CanvasDrawingSession ds, float width, float height) { using (var cl = new CanvasCommandList(ds)) { using (var clds = cl.CreateDrawingSession()) { var text = string.Format("{0}\n{1}", DateTime.Now.ToString("ddd"), DateTime.Now.ToString("HH:mm")); var textFormat = new CanvasTextFormat() { FontFamily = "Segoe UI Black", HorizontalAlignment = CanvasHorizontalAlignment.Right, VerticalAlignment = CanvasVerticalAlignment.Center, FontSize = 20, LineSpacing = 20 }; clds.DrawText(text, 0, 0, Colors.White, textFormat); } var effect = new GaussianBlurEffect() { Source = cl, BlurAmount = 1, }; ds.Clear(Colors.Orange); var bounds = effect.GetBounds(ds); var ratio = bounds.Height / bounds.Width; var destHeight = height * ratio; ds.DrawImage(effect, new Rect(0, height / 2 - destHeight / 2, width, destHeight), bounds); ds.DrawText(string.Format("Generated by Win2D\n{0}\n{1}", DateTime.Now.ToString("d"), DateTime.Now.ToString("t")), 12, 12, Colors.Black, new CanvasTextFormat() { HorizontalAlignment = CanvasHorizontalAlignment.Left, VerticalAlignment = CanvasVerticalAlignment.Top, FontSize = 12 }); } }
CompositionDrawingSurface ApplyBlurEffect(CanvasBitmap bitmap, Windows.UI.Composition.CompositionGraphicsDevice device, Size sizeTarget) { GaussianBlurEffect blurEffect = new GaussianBlurEffect() { Source = bitmap, BlurAmount = 20.0f }; float fDownsample = .3f; Size sizeSource = bitmap.Size; if (sizeTarget == Size.Empty) { sizeTarget = sizeSource; } sizeTarget = new Size(sizeTarget.Width * fDownsample, sizeTarget.Height * fDownsample); CompositionDrawingSurface blurSurface = device.CreateDrawingSurface(sizeTarget, DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied); using (var ds = CanvasComposition.CreateDrawingSession(blurSurface)) { Rect destination = new Rect(0, 0, sizeTarget.Width, sizeTarget.Height); ds.Clear(Windows.UI.Color.FromArgb(255, 255, 255, 255)); ds.DrawImage(blurEffect, destination, new Rect(0, 0, sizeSource.Width, sizeSource.Height)); } return blurSurface; }
private async void UpdateEffect() { if (_compositor != null) { ComboBoxItem item = EffectSelection.SelectedValue as ComboBoxItem; IGraphicsEffect graphicsEffect = null; CompositionBrush secondaryBrush = null; string[] animatableProperties = null; // // Create the appropriate effect graph and resources // switch ((EffectTypes)item.Tag) { case EffectTypes.Desaturation: { graphicsEffect = new SaturationEffect() { Saturation = 0.0f, Source = new CompositionEffectSourceParameter("ImageSource") }; } break; case EffectTypes.Hue: { graphicsEffect = new HueRotationEffect() { Name = "Hue", Angle = 3.14f, Source = new CompositionEffectSourceParameter("ImageSource") }; animatableProperties = new[] { "Hue.Angle" }; } break; case EffectTypes.VividLight: { graphicsEffect = new BlendEffect() { Mode = BlendEffectMode.VividLight, Foreground = new ColorSourceEffect() { Name = "Base", Color = Color.FromArgb(255,80,40,40) }, Background = new CompositionEffectSourceParameter("ImageSource"), }; animatableProperties = new[] { "Base.Color" }; } break; case EffectTypes.Mask: { graphicsEffect = new CompositeEffect() { Mode = CanvasComposite.DestinationOver, Sources = { new CompositeEffect() { Mode = CanvasComposite.DestinationIn, Sources = { new CompositionEffectSourceParameter("ImageSource"), new CompositionEffectSourceParameter("SecondSource") } }, new ColorSourceEffect() { Color = Color.FromArgb(200,255,255,255) }, } }; CompositionDrawingSurface backgroundSurface = await SurfaceLoader.LoadFromUri(new Uri("ms-appx:///Samples/SDK Insider/ForegroundFocusEffects/mask.png")); CompositionSurfaceBrush maskBrush = _compositor.CreateSurfaceBrush(backgroundSurface); maskBrush.Stretch = CompositionStretch.UniformToFill; maskBrush.CenterPoint = backgroundSurface.Size.ToVector2() / 2; secondaryBrush = maskBrush; } break; case EffectTypes.Blur: { graphicsEffect = new GaussianBlurEffect() { BlurAmount = 20, Source = new CompositionEffectSourceParameter("ImageSource"), Optimization = EffectOptimization.Balanced, BorderMode = EffectBorderMode.Hard, }; } break; case EffectTypes.LightenBlur: { graphicsEffect = new ArithmeticCompositeEffect() { Source1Amount = .4f, Source2Amount = .6f, MultiplyAmount = 0, Source1 = new ColorSourceEffect() { Name = "Base", Color = Color.FromArgb(255, 255, 255, 255), }, Source2 = new GaussianBlurEffect() { BlurAmount = 20, Source = new CompositionEffectSourceParameter("ImageSource"), Optimization = EffectOptimization.Balanced, BorderMode = EffectBorderMode.Hard, } }; } break; case EffectTypes.DarkenBlur: { graphicsEffect = new ArithmeticCompositeEffect() { Source1Amount = .4f, Source2Amount = .6f, MultiplyAmount = 0, Source1 = new ColorSourceEffect() { Name = "Base", Color = Color.FromArgb(255, 0, 0, 0), }, Source2 = new GaussianBlurEffect() { BlurAmount = 20, Source = new CompositionEffectSourceParameter("ImageSource"), Optimization = EffectOptimization.Balanced, BorderMode= EffectBorderMode.Hard, } }; } break; case EffectTypes.RainbowBlur: { graphicsEffect = new ArithmeticCompositeEffect() { Source1Amount = .3f, Source2Amount = .7f, MultiplyAmount = 0, Source1 = new ColorSourceEffect() { Name = "Base", Color = Color.FromArgb(255, 0, 0, 0), }, Source2 = new GaussianBlurEffect() { BlurAmount = 20, Source = new CompositionEffectSourceParameter("ImageSource"), Optimization = EffectOptimization.Balanced, BorderMode = EffectBorderMode.Hard, } }; animatableProperties = new[] { "Base.Color" }; } break; default: break; } // Create the effect factory and instantiate a brush CompositionEffectFactory _effectFactory = _compositor.CreateEffectFactory(graphicsEffect, animatableProperties); CompositionEffectBrush brush = _effectFactory.CreateBrush(); // Set the destination brush as the source of the image content brush.SetSourceParameter("ImageSource", _compositor.CreateBackdropBrush()); // If his effect uses a secondary brush, set it now if (secondaryBrush != null) { brush.SetSourceParameter("SecondSource", secondaryBrush); } // Update the destination layer with the fully configured brush _destinationSprite.Brush = brush; } }
private void OnDraw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args) { var textDisplay = GenerateTextDisplay(sender, (float)sender.Size.Width, (float)sender.Size.Height); var blurEffect = new GaussianBlurEffect() { Source = textDisplay, BlurAmount = 10 }; textOpacityBrush.StartPoint = blurOpacityBrush.StartPoint = new Vector2(0,0); textOpacityBrush.EndPoint = blurOpacityBrush.EndPoint = new Vector2(0, (float)sender.Size.Height); var ds = args.DrawingSession; using (ds.CreateLayer(blurOpacityBrush)) { ds.DrawImage(blurEffect); } using (ds.CreateLayer(textOpacityBrush)) { ds.DrawImage(textDisplay); } }
private void Canvas_CreateResources(CanvasAnimatedControl sender, CanvasCreateResourcesEventArgs args) { _effect = new GaussianBlurEffect() { BlurAmount = 5, BorderMode = EffectBorderMode.Hard }; }