private void NowPlaying_Loaded(object sender, RoutedEventArgs e) { var visual = ElementCompositionPreview.GetElementVisual(this.backgroundLarge); this.compositor = visual.Compositor; var backgroundBrush = this.compositor.CreateBackdropBrush(); var saturationEffect = new SaturationEffect { Saturation = 0.0f, Source = new CompositionEffectSourceParameter("mySource") }; var saturationEffectFactory = this.compositor.CreateEffectFactory(saturationEffect); var bwEffect = saturationEffectFactory.CreateBrush(); bwEffect.SetSourceParameter("mySource", backgroundBrush); this.backgroundVisual = this.compositor.CreateSpriteVisual(); this.backgroundVisual.Brush = bwEffect; this.backgroundVisual.Size = this.rootElement.RenderSize.ToVector2(); this.containerVisual = this.compositor.CreateContainerVisual(); this.containerVisual.Children.InsertAtBottom(this.backgroundVisual); ElementCompositionPreview.SetElementChildVisual(this.backgroundLarge, this.containerVisual); this.AddLighting(); this.AnimateColorChange(); this.AnimateLightMovement(); }
private CompositionEffectBrush CreateBlurBrush() { var blurEffect = new GaussianBlurEffect { Name = "Blur", BorderMode = EffectBorderMode.Hard, Optimization = EffectOptimization.Balanced, Source = new CompositionEffectSourceParameter("Source"), BlurAmount = 0 }; var blendEffect = new BlendEffect { Background = blurEffect, Foreground = new ColorSourceEffect { Name = "Color", Color = Colors.Transparent }, Mode = BlendEffectMode.LighterColor }; var saturationEffect = new SaturationEffect { Source = blendEffect, Saturation = 1.75f }; var effectFactory = _compositor.CreateEffectFactory(saturationEffect, new[] { "Blur.BlurAmount", "Color.Color" }); var effectBrush = effectFactory.CreateBrush(); return(effectBrush); }
public void Desaturate() { // Create and setup an instance of the effect for the visual //Create CompositionSurfaceBrush CompositionSurfaceBrush surfaceBrush = _compositor.CreateSurfaceBrush(); LoadImage(surfaceBrush, new Uri("ms-appx:///Assets/cat.png")); // Create the graphics effect var graphicsEffect = new SaturationEffect { Saturation = 0.0f, Source = new CompositionEffectSourceParameter("mySource") }; // Compile the effect var effectFactory = _compositor.CreateEffectFactory(graphicsEffect); var catEffect = effectFactory.CreateBrush(); catEffect.SetSourceParameter("mySource", surfaceBrush); // Create the visual and add it to the composition tree var catVisual = _compositor.CreateSpriteVisual(); catVisual.Brush = catEffect; catVisual.Size = new Vector2(219, 300); _root.Children.InsertAtBottom(catVisual); }
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, }; }
public object Convert(object value, Type targetType, object parameter, string language) { var id = (int)value; //DataTemplate dt = null; //switch (id) { // case 1: dt = (DataTemplate)App.Current.Resources.MergedDictionaries[2]["dtGS"]; break; // case 2: dt = (DataTemplate)App.Current.Resources.MergedDictionaries[2]["dtSat"]; break; // default: dt = (DataTemplate)App.Current.Resources.MergedDictionaries[2]["dtGS"]; break; //} //return dt; var effect = new SaturationEffect(); effect.Level = 150; effect.Source = (string)parameter; var grd = new Grid(); grd.SetValue(Composition.EffectProperty, effect); return(grd); }
public void Desaturate() { // Create and setup an instance of the effect for the visual var graphicsDevice = _compositor.DefaultGraphicsDevice; var catImage = graphicsDevice.CreateImageFromUri(new Uri("ms-appx:///Assets/cat.png")); // Create the graphics effect var graphicsEffect = new SaturationEffect { Saturation = 0.0f, Source = new CompositionEffectSourceParameter("mySource") }; // Compile the effect var effectFactory = _compositor.CreateEffectFactory(graphicsEffect); var catEffect = effectFactory.CreateEffect(); catEffect.SetSourceParameter("mySource", catImage); // Create the visual and add it to the composition tree var catVisual = _compositor.CreateEffectVisual(); catVisual.Effect = catEffect; catVisual.Size = new Vector2(219, 300); _root.Children.InsertAtBottom(catVisual); }
#pragma warning disable 1998 public override async Task <CompositionDrawingSurface> LoadResources() { // Create the effect template var graphicsEffect = new SaturationEffect { Name = _effectName, Saturation = 1.0f, Source = new CompositionEffectSourceParameter("ImageSource") }; _effectFactory = _compositor.CreateEffectFactory(graphicsEffect, new[] { _targetProperty }); // Create the animations _enterAnimation = _compositor.CreateScalarKeyFrameAnimation(); _enterAnimation.InsertKeyFrame(1f, 0f); _enterAnimation.Duration = TimeSpan.FromMilliseconds(1000); _enterAnimation.IterationBehavior = AnimationIterationBehavior.Count; _enterAnimation.IterationCount = 1; _exitAnimation = _compositor.CreateScalarKeyFrameAnimation(); _exitAnimation.InsertKeyFrame(1f, 1f); _exitAnimation.Duration = TimeSpan.FromMilliseconds(1000); _exitAnimation.IterationBehavior = AnimationIterationBehavior.Count; _exitAnimation.IterationCount = 1; return(null); }
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 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"); } }
public void Desaturate() { // Create and setup an instance of the effect for the visual var graphicsDevice = _compositor.DefaultGraphicsDevice; var catImage = graphicsDevice.CreateImageFromUri(new Uri("ms-appx:///Assets/cat.png")); // Create the graphics effect var graphicsEffect = new SaturationEffect { Saturation = 0.0f, Source = new CompositionEffectSourceParameter("mySource") }; // Compile the effect var effectFactory = _compositor.CreateEffectFactory(graphicsEffect); var catEffect = effectFactory.CreateEffect(); catEffect.SetSourceParameter("mySource", catImage); // Create the visual and add it to the composition tree var catVisual = _compositor.CreateEffectVisual(); catVisual.Effect = catEffect; catVisual.Size = new Vector2(219, 300); _root.Children.InsertAtBottom(catVisual); }
public void Desaturate() { // Create and setup an instance of the effect for the visual //Create CompositionSurfaceBrush CompositionSurfaceBrush surfaceBrush = _compositor.CreateSurfaceBrush(); LoadImage(surfaceBrush, new Uri("ms-appx:///Assets/cat.png")); // Create the graphics effect var graphicsEffect = new SaturationEffect { Saturation = 0.0f, Source = new CompositionEffectSourceParameter("mySource") }; // Compile the effect var effectFactory = _compositor.CreateEffectFactory(graphicsEffect); var catEffect = effectFactory.CreateBrush(); catEffect.SetSourceParameter("mySource", surfaceBrush); // Create the visual and add it to the composition tree var catVisual = _compositor.CreateSpriteVisual(); catVisual.Brush = catEffect; catVisual.Size = new Vector2(219, 300); _root.Children.InsertAtBottom(catVisual); }
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); }
public static async Task <AttachedCompositeAnimatableCompositionEffect <T> > AttachCompositionAnimatableBlurAndSaturationEffectAsync <T>( [NotNull] this T element, float onBlur, float offBlur, float onSaturation, float offSaturation, bool initiallyVisible, bool disposeOnUnload = false) where T : FrameworkElement { // Get the compositor Visual visual = await DispatcherHelper.GetFromUIThreadAsync(element.GetVisual); Compositor compositor = visual.Compositor; // Create the blur effect, the saturation effect and the effect factory GaussianBlurEffect blurEffect = new GaussianBlurEffect { Name = "Blur", BlurAmount = 0f, BorderMode = EffectBorderMode.Hard, Optimization = EffectOptimization.Balanced, Source = new CompositionEffectSourceParameter("source") }; SaturationEffect saturationEffect = new SaturationEffect { Name = "SEffect", Saturation = initiallyVisible ? offSaturation : onSaturation, Source = blurEffect }; const String blurParameter = "Blur.BlurAmount", saturationParameter = "SEffect.Saturation"; CompositionEffectFactory effectFactory = compositor.CreateEffectFactory(saturationEffect, new[] { blurParameter, saturationParameter }); // Setup the rest of the effect CompositionEffectBrush effectBrush = effectFactory.CreateBrush(); effectBrush.SetSourceParameter("source", compositor.CreateBackdropBrush()); // Assign the effect to a brush and display it SpriteVisual sprite = compositor.CreateSpriteVisual(); sprite.Brush = effectBrush; await AddToTreeAndBindSizeAsync(visual, element, sprite); if (initiallyVisible) { await DispatcherHelper.RunOnUIThreadAsync(() => element.Opacity = 1); } // Prepare and return the wrapped effect return(new AttachedCompositeAnimatableCompositionEffect <T>(element, sprite, new Dictionary <String, CompositionAnimationValueParameters> { { blurParameter, new CompositionAnimationValueParameters(onBlur, offBlur) }, { saturationParameter, new CompositionAnimationValueParameters(onSaturation, offSaturation) } }, disposeOnUnload)); }
public void ProcessFrame(ProcessVideoFrameContext context) { // If memory type is CPU, the frame is in InputFrame.SoftwareBitmap. // For GPU, the frame is in InputFrame.Direct3DSurface if (context.InputFrame.SoftwareBitmap == null) { using (var inputBitmap = CanvasBitmap.CreateFromDirect3D11Surface(_canvasDevice, context.InputFrame.Direct3DSurface)) using (var renderTarget = CanvasRenderTarget.CreateFromDirect3D11Surface(_canvasDevice, context.OutputFrame.Direct3DSurface)) using (var ds = renderTarget.CreateDrawingSession()) { var saturation = new SaturationEffect() { Source = inputBitmap, Saturation = this.Intensity }; ds.DrawImage(saturation); } return; } if (context.InputFrame.Direct3DSurface == null) { // InputFrame's raw pixels byte[] inputFrameBytes = new byte[4 * context.InputFrame.SoftwareBitmap.PixelWidth * context.InputFrame.SoftwareBitmap.PixelHeight]; context.InputFrame.SoftwareBitmap.CopyToBuffer(inputFrameBytes.AsBuffer()); using (var inputBitmap = CanvasBitmap.CreateFromBytes( _canvasDevice, inputFrameBytes, context.InputFrame.SoftwareBitmap.PixelWidth, context.InputFrame.SoftwareBitmap.PixelHeight, context.InputFrame.SoftwareBitmap.BitmapPixelFormat.ToDirectXPixelFormat())) using (var renderTarget = new CanvasRenderTarget( _canvasDevice, context.OutputFrame.SoftwareBitmap.PixelWidth, context.OutputFrame.SoftwareBitmap.PixelHeight, (float)context.OutputFrame.SoftwareBitmap.DpiX, context.OutputFrame.SoftwareBitmap.BitmapPixelFormat.ToDirectXPixelFormat(), CanvasAlphaMode.Premultiplied)) { using (var ds = renderTarget.CreateDrawingSession()) { var saturation = new SaturationEffect() { Source = inputBitmap, Saturation = this.Intensity }; ds.DrawImage(saturation); } } } }
private void UpdateBrush() { if (m_isDisabledByPolicy && m_brush is CompositionEffectBrush) { m_brush.Dispose(); m_brush = null; } if (m_brush == null) { if (m_isDisabledByPolicy) { m_brush = Window.Current.Compositor.CreateColorBrush(FallbackColor); CompositionBrush = m_brush; } else { var gaussianBlur = new GaussianBlurEffect { Name = "Blur", BlurAmount = 30, Optimization = EffectOptimization.Speed, BorderMode = EffectBorderMode.Hard, Source = new CompositionEffectSourceParameter("Backdrop") }; var saturationEffect = new SaturationEffect { Name = "Saturation", Saturation = 1.7f, Source = gaussianBlur }; var tintColorEffect = new ColorSourceEffect { Name = "TintColor", Color = Color.FromArgb(52, 0, 0, 0) }; var compositeEffect = new CompositeEffect(); compositeEffect.Mode = CanvasComposite.SourceOver; compositeEffect.Sources.Add(saturationEffect); compositeEffect.Sources.Add(tintColorEffect); var effectFactory = Window.Current.Compositor.CreateEffectFactory(compositeEffect); var backdrop = Window.Current.Compositor.CreateBackdropBrush(); var brush = effectFactory.CreateBrush(); brush.SetSourceParameter("Backdrop", backdrop); m_brush = brush; CompositionBrush = m_brush; } } }
private void MainPage_Loaded(object sender, RoutedEventArgs e) { var compositor = Window.Current.Compositor; _surface = LoadedImageSurface.StartLoadFromUri(new Uri("ms-appx:///Assets/webster-pass.png")); var backgroundBrush = compositor.CreateSurfaceBrush(_surface); backgroundBrush.Stretch = CompositionStretch.UniformToFill; var saturationEffect = new SaturationEffect { Saturation = 0.0f, Source = new CompositionEffectSourceParameter("mySource") }; var saturationEffectFactory = compositor.CreateEffectFactory(saturationEffect); var bwEffect = saturationEffectFactory.CreateBrush(); bwEffect.SetSourceParameter("mySource", backgroundBrush); _backgroundVisual = compositor.CreateSpriteVisual(); _backgroundVisual.Brush = bwEffect; _backgroundVisual.Size = RootElement.RenderSize.ToVector2(); _containerVisual = compositor.CreateContainerVisual(); _containerVisual.Children.InsertAtBottom(_backgroundVisual); ElementCompositionPreview.SetElementChildVisual(RootElement, _containerVisual); // Text _surfaceFactory = SurfaceFactory.GetSharedSurfaceFactoryForCompositor(compositor); _textSurface = _surfaceFactory.CreateTextSurface("Weston Pass"); _textSurface.ForegroundColor = Color.FromArgb(50, 255, 255, 255); _textSurface.FontSize = 150; var textSurfaceBrush = compositor.CreateSurfaceBrush(_textSurface.Surface); _textVisual = compositor.CreateSpriteVisual(); _textVisual.Size = _textSurface.Size.ToVector2(); _textVisual.RotationAngleInDegrees = 45f; _textVisual.AnchorPoint = new Vector2(0.5f); _textVisual.Brush = textSurfaceBrush; _textVisual.StartAnimation(nameof(Visual.Offset), CreateTextOffsetAnimation( new Vector3((float)RootElement.ActualWidth / 2, (float)RootElement.ActualWidth / 2, 0))); _containerVisual.Children.InsertAtTop(_textVisual); AddLighting(); StartLightingAnimationTimer(); }
/// <summary> /// Creates a CompositionEffectFactory that creates SaturationEffects. /// </summary> /// <returns>CompositionEffectFactory</returns> private CompositionEffectFactory CreateSaturationEffectFactory() { var effectDefinition = new SaturationEffect() { Name = "Saturation", Saturation = 0.0f, Source = new CompositionEffectSourceParameter("Video") }; return(_compositor.CreateEffectFactory(effectDefinition, new string[] { "Saturation.Saturation" })); }
async Task Canvas_CreateResourcesAsync(CanvasControl sender) { bitmap = await CanvasBitmap.LoadAsync(sender, "imageTiger.jpg"); redBrush = CreateGradientBrush(sender, 255, 0, 0); greenBrush = CreateGradientBrush(sender, 0, 255, 0); blueBrush = CreateGradientBrush(sender, 0, 0, 255); brightnessEffect = new BrightnessEffect { Source = bitmap }; saturationEffect = new SaturationEffect { Source = brightnessEffect }; hueEffect = new HueRotationEffect { Source = saturationEffect }; }
private ICanvasImage GetSaturationEffect(ICanvasImage source) { var t = (saturation.Value + 100) * 0.01; var saturationEffect = new SaturationEffect { Source = source, Saturation = (float)t //Saturation = 2 }; return(saturationEffect); }
// Use this for initialization void Awake() { if (instance != null) { Debug.LogError("Already a GameManager(Singleton) in this scene; conflict between '" + instance.gameObject.name + "' and '" + gameObject.name); return; } instance = this; GameObject go = GameObject.FindGameObjectWithTag(Constants.BWCamera); if (go != null) { saturationEffectScript = go.GetComponent<SaturationEffect>(); } }
public EffectNineGridScenario(Compositor compositor, CompositionNineGridBrush sourceNineGridBrush, string text) { var saturationEffect = new SaturationEffect { Saturation = 0f, Source = new CompositionEffectSourceParameter("sourceNineGridBrush"), }; var saturationFactory = compositor.CreateEffectFactory(saturationEffect); _nineGridEffectBrush = saturationFactory.CreateBrush(); _nineGridEffectBrush.SetSourceParameter("sourceNineGridBrush", sourceNineGridBrush); //takes a ninegrid source as input _text = text; }
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 saturation = new SaturationEffect() { Source = inputBitmap, Saturation = this.Saturation }; ds.DrawImage(saturation); } }
private ICanvasImage CreateSaturation() { var saturationEffect = new SaturationEffect { Source = bitmapTiger }; // Animation changes the saturation amount. animationFunction = elapsedTime => { saturationEffect.Saturation = ((float)Math.Sin(elapsedTime * 6) + 1) / 2; }; return(saturationEffect); }
public static void Initialize(Compositor compositor) { s_random = new Random(); s_compositor = compositor; // Create a animatable desaturation effect description var effectDesc = new SaturationEffect(); effectDesc.Name = "myEffect"; effectDesc.Source = new CompositionEffectSourceParameter("Image"); s_saturationEffectFactory = compositor.CreateEffectFactory( effectDesc, new string[] { "myEffect.Saturation" }); }
public PerDeviceResources(ICanvasResourceCreatorWithDpi resourceCreator) { ResourceCreator = resourceCreator; DefaultDpiBitmap = CreateTestBitmap(resourceCreator, defaultDpi); HighDpiBitmap = CreateTestBitmap(resourceCreator, highDpi); LowDpiBitmap = CreateTestBitmap(resourceCreator, lowDpi); AutoDpiRenderTarget = new CanvasRenderTarget(resourceCreator, testSize, testSize); HighDpiRenderTarget = new CanvasRenderTarget(resourceCreator, testSize, testSize, highDpi); LowDpiRenderTarget = new CanvasRenderTarget(resourceCreator, testSize, testSize, lowDpi); SaturationEffect = new SaturationEffect { Saturation = 0 }; }
/// <summary> /// Show Compositon effects on image /// </summary> /// <param name="imageURL">Image to effect</param> private void SetupComposition(Uri imageURL) { try { CompositionSurfaceBrush _imageBrush; Compositor _compositor = Window.Current.Compositor; _imageBrush = _compositor.CreateSurfaceBrush(); _imageBrush.Stretch = CompositionStretch.UniformToFill; LoadedImageSurface _loadedSurface = LoadedImageSurface.StartLoadFromUri(imageURL); _loadedSurface.LoadCompleted += _loadedSurface_LoadCompleted; _imageBrush.Surface = _loadedSurface; // Saturate var saturationEffect = new SaturationEffect { Saturation = 1, Source = new CompositionEffectSourceParameter("image") }; var effectFactory = _compositor.CreateEffectFactory(saturationEffect); var effectBrush = effectFactory.CreateBrush(); effectBrush.SetSourceParameter("image", _imageBrush); // Blur var blurEffect = new GaussianBlurEffect { BlurAmount = 8, Source = new CompositionEffectSourceParameter("image") }; var effectFactory2 = _compositor.CreateEffectFactory(blurEffect); var effectBrush2 = effectFactory2.CreateBrush(); effectBrush2.SetSourceParameter("image", effectBrush); _imageVisual = _compositor.CreateSpriteVisual(); _imageVisual.Brush = effectBrush2; _imageVisual.Size = new Vector2(Convert.ToSingle(BackgroundContainer.ActualWidth), Convert.ToSingle(BackgroundContainer.ActualHeight)); ElementCompositionPreview.SetElementChildVisual(BackgroundContainer, _imageVisual); } catch { // I guess it'll just look meh } }
/// <summary> /// Applies the effect. /// </summary> /// <returns> /// An array of strings of the effect properties to change. /// </returns> public override string[] ApplyEffect() { var saturationEffect = new SaturationEffect { Saturation = 1f, Name = EffectName, Source = new CompositionEffectSourceParameter("source") }; var propertyToChange = $"{EffectName}.Saturation"; var propertiesToAnimate = new[] { propertyToChange }; EffectBrush = Compositor.CreateEffectFactory(saturationEffect, propertiesToAnimate).CreateBrush(); EffectBrush.SetSourceParameter("source", Compositor.CreateBackdropBrush()); return(propertiesToAnimate); }
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; }
public static void Initialize(Compositor compositor) { s_random = new Random(); s_compositor = compositor; // Create a animatable desaturation effect description var effectDesc = new SaturationEffect(); effectDesc.Name = "myEffect"; effectDesc.Source = new CompositionEffectSourceParameter("Image"); s_saturationEffectFactory = compositor.CreateEffectFactory( effectDesc, new string[] { "myEffect.Saturation" }); }
async Task Canvas_CreateResourcesAsync(CanvasControl sender) { bitmap = await CanvasBitmap.LoadAsync(sender, "imageTiger.jpg"); redBrush = CreateGradientBrush(sender, 255, 0, 0); greenBrush = CreateGradientBrush(sender, 0, 255, 0); blueBrush = CreateGradientBrush(sender, 0, 0, 255); brightnessEffect = new BrightnessEffect { Source = bitmap }; saturationEffect = new SaturationEffect { Source = brightnessEffect }; hueEffect = new HueRotationEffect { Source = saturationEffect }; }
public void Desaturate() { // Create and setup an instance of the effect for the visual // Create CompositionSurfaceBrush CompositionSurfaceBrush surfaceBrush = _compositor.CreateSurfaceBrush(); LoadImage(surfaceBrush); // Create the graphics effect var graphicsEffect = new SaturationEffect { Name = "SaturationEffect", Saturation = 0.0f, Source = new CompositionEffectSourceParameter("mySource") }; // Compile the effect specifying saturation is an animatable property var effectFactory = _compositor.CreateEffectFactory(graphicsEffect, new[] { "SaturationEffect.Saturation" }); _catEffect = effectFactory.CreateBrush(); _catEffect.SetSourceParameter("mySource", surfaceBrush); _catEffect.Properties.InsertScalar("saturationEffect.Saturation", 0f); // Create a ScalarKeyFrame to that will be used to animate the Saturation property of an Effect ScalarKeyFrameAnimation effectAnimation = _compositor.CreateScalarKeyFrameAnimation(); effectAnimation.InsertKeyFrame(0f, 0f); effectAnimation.InsertKeyFrame(0.50f, 1f); effectAnimation.InsertKeyFrame(1.0f, 0f); effectAnimation.Duration = TimeSpan.FromMilliseconds(2500); effectAnimation.IterationBehavior = AnimationIterationBehavior.Forever; // Start the Animation on the Saturation property of the Effect _catEffect.Properties.StartAnimation("saturationEffect.Saturation", effectAnimation); // Create the visual and add it to the composition tree var catVisual = _compositor.CreateSpriteVisual(); catVisual.Brush = _catEffect; catVisual.Size = new Vector2(219, 300); _root.Children.InsertAtBottom(catVisual); }
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); }
public CompositionEffectBrush CreateEffectBrush( EffectType effectType, string effectName, float propertyValue, IEnumerable <string> properties) { IGraphicsEffect effectDesc = null; switch (effectType) { case EffectType.Saturation: effectDesc = new SaturationEffect() { Name = effectName, Saturation = propertyValue, Source = new CompositionEffectSourceParameter("source") }; break; case EffectType.HueRotation: effectDesc = new HueRotationEffect() { Name = effectName, Angle = propertyValue, Source = new CompositionEffectSourceParameter("source") }; break; case EffectType.Sepia: effectDesc = new SepiaEffect() { Name = effectName, Intensity = propertyValue, Source = new CompositionEffectSourceParameter("source") }; break; } CompositionEffectFactory effectFactory = _compositor.CreateEffectFactory(effectDesc, properties); CompositionEffectBrush effectBrush = effectFactory.CreateBrush(); return(effectBrush); }
protected override void BuildBrush() { var compositor = Window.Current.Compositor; _effectVisual = compositor.CreateSpriteVisual(); var graphicsEffect = new SaturationEffect() { Name = "SaturationEffect", Saturation = (float)SaturationSlider.Value, Source = new CompositionEffectSourceParameter("Background") }; var effectFactory = compositor.CreateEffectFactory(graphicsEffect, new [] { "SaturationEffect.Saturation" }); _effectBrush = effectFactory.CreateBrush(); _effectBrush.SetSourceParameter("Background", compositor.CreateBackdropBrush()); _effectVisual.Brush = _effectBrush; ResizeVisual(); ElementCompositionPreview.SetElementChildVisual(TargetElement, _effectVisual); }
void Canvas_CreateResources(CanvasControl sender, object args) { defaultDpiBitmap = CreateTestBitmap(sender, defaultDpi); highDpiBitmap = CreateTestBitmap(sender, highDpi); lowDpiBitmap = CreateTestBitmap(sender, lowDpi); autoDpiRenderTarget = new CanvasRenderTarget(sender, testSize, testSize); highDpiRenderTarget = new CanvasRenderTarget(sender, testSize, testSize, highDpi); lowDpiRenderTarget = new CanvasRenderTarget(sender, testSize, testSize, lowDpi); saturationEffect = new SaturationEffect { Saturation = 0 }; imageBrush = new CanvasImageBrush(sender); imageSource = new CanvasImageSource(sender, controlSize, controlSize); imageControl.Source = imageSource; swapChain = new CanvasSwapChain(sender, controlSize, controlSize); swapChainPanel.SwapChain = swapChain; }
public void Desaturate() { // Create and setup an instance of the effect for the visual // Create CompositionSurfaceBrush CompositionSurfaceBrush surfaceBrush = _compositor.CreateSurfaceBrush(); LoadImage(surfaceBrush); // Create the graphics effect var graphicsEffect = new SaturationEffect { Name = "SaturationEffect", Saturation = 0.0f, Source = new CompositionEffectSourceParameter("mySource") }; // Compile the effect specifying saturation is an animatable property var effectFactory = _compositor.CreateEffectFactory(graphicsEffect, new[] { "SaturationEffect.Saturation" }); _catEffect = effectFactory.CreateBrush(); _catEffect.SetSourceParameter("mySource", surfaceBrush); _catEffect.Properties.InsertScalar("saturationEffect.Saturation", 0f); // Create a ScalarKeyFrame to that will be used to animate the Saturation property of an Effect ScalarKeyFrameAnimation effectAnimation = _compositor.CreateScalarKeyFrameAnimation(); effectAnimation.InsertKeyFrame(0f, 0f); effectAnimation.InsertKeyFrame(0.50f, 1f); effectAnimation.InsertKeyFrame(1.0f, 0f); effectAnimation.Duration = TimeSpan.FromMilliseconds(2500); effectAnimation.IterationBehavior = AnimationIterationBehavior.Forever; // Start the Animation on the Saturation property of the Effect _catEffect.Properties.StartAnimation("saturationEffect.Saturation", effectAnimation); // Create the visual and add it to the composition tree var catVisual = _compositor.CreateSpriteVisual(); catVisual.Brush = _catEffect; catVisual.Size = new Vector2(219, 300); _root.Children.InsertAtBottom(catVisual); }
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 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 ICanvasImage CreateSaturation() { var saturationEffect = new SaturationEffect { Source = bitmapTiger }; // Animation changes the saturation amount. animationFunction = elapsedTime => { saturationEffect.Saturation = ((float)Math.Sin(elapsedTime * 6) + 1) / 2; }; return saturationEffect; }
PerDeviceResources(ICanvasResourceCreatorWithDpi resourceCreator, CanvasVirtualBitmap virtualBitmap) { ResourceCreator = resourceCreator; DefaultDpiBitmap = CreateTestBitmap(resourceCreator, defaultDpi); HighDpiBitmap = CreateTestBitmap(resourceCreator, highDpi); LowDpiBitmap = CreateTestBitmap(resourceCreator, lowDpi); VirtualBitmap = virtualBitmap; AutoDpiRenderTarget = new CanvasRenderTarget(resourceCreator, testSize, testSize); HighDpiRenderTarget = new CanvasRenderTarget(resourceCreator, testSize, testSize, highDpi); LowDpiRenderTarget = new CanvasRenderTarget(resourceCreator, testSize, testSize, lowDpi); SaturationEffect = new SaturationEffect { Saturation = 0 }; }
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 saturation = new SaturationEffect() { Source = inputBitmap, Saturation = this.Saturation }; ds.DrawImage(saturation); } }
/// <summary> /// Creates a CompositionEffectFactory that creates SaturationEffects. /// </summary> /// <returns>CompositionEffectFactory</returns> private CompositionEffectFactory CreateSaturationEffectFactory() { var effectDefinition = new SaturationEffect() { Name = "Saturation", Saturation = 0.0f, Source = new CompositionEffectSourceParameter("Video") }; return _compositor.CreateEffectFactory(effectDefinition, new string[] { "Saturation.Saturation" }); }
public CompositionEffectBrush CreateEffectBrush( EffectType effectType, string effectName, float propertyValue, IEnumerable<string> properties) { IGraphicsEffect effectDesc = null; switch (effectType) { case EffectType.Saturation: effectDesc = new SaturationEffect() { Name = effectName, Saturation = propertyValue, Source = new CompositionEffectSourceParameter("source") }; break; case EffectType.HueRotation: effectDesc = new HueRotationEffect() { Name = effectName, Angle = propertyValue, Source = new CompositionEffectSourceParameter("source") }; break; case EffectType.Sepia: effectDesc = new SepiaEffect() { Name = effectName, Intensity = propertyValue, Source = new CompositionEffectSourceParameter("source") }; break; } CompositionEffectFactory effectFactory = _compositor.CreateEffectFactory(effectDesc, properties); CompositionEffectBrush effectBrush = effectFactory.CreateBrush(); return effectBrush; }
#pragma warning disable 1998 public override async Task<CompositionDrawingSurface> LoadResources() { // Create the effect template var graphicsEffect = new SaturationEffect { Name = _effectName, Saturation = 1.0f, Source = new CompositionEffectSourceParameter("ImageSource") }; _effectFactory = _compositor.CreateEffectFactory(graphicsEffect, new[] { _targetProperty }); // Create the animations _enterAnimation = _compositor.CreateScalarKeyFrameAnimation(); _enterAnimation.InsertKeyFrame(1f, 0f); _enterAnimation.Duration = TimeSpan.FromMilliseconds(1000); _enterAnimation.IterationBehavior = AnimationIterationBehavior.Count; _enterAnimation.IterationCount = 1; _exitAnimation = _compositor.CreateScalarKeyFrameAnimation(); _exitAnimation.InsertKeyFrame(1f, 1f); _exitAnimation.Duration = TimeSpan.FromMilliseconds(1000); _exitAnimation.IterationBehavior = AnimationIterationBehavior.Count; _exitAnimation.IterationCount = 1; return null; }
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 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 CreateEffect() { effect = new SaturationEffect() { Name = SaturationEffect, Saturation = 0.0f, Source = new CompositionEffectSourceParameter(EffectSource) }; UpdateLevel(); effectFactory = compositor.CreateEffectFactory(effect, new[] { SaturationEffectPath }); }