[UWP][Win2D]How to apply both HueRotationEffect and ContrastEffect using Win2D? RRS feed

  • Question

  • Hi,

    I want to apply both HueRotationEffect and ContrastEffect at the same time to the image. How to apply more than one effect to the image?


    Santhiya A

    Friday, September 20, 2019 1:43 PM

All replies

  • Hi,

    I made a simple try with the official sample:Win2d-ExampleGallery. A possible way is that when you had created a HueRotationEffect, created a ContrastEffect using HueRotationEffect as source. Like the following code:

     private ICanvasImage CreateContrast()
                var hueRotationEffect = new HueRotationEffect
                    Source = bitmapTiger
                var contrastEffect = new ContrastEffect
                    Source = hueRotationEffect
                // Animation changes the image contrast.
                animationFunction = elapsedTime =>
                    hueRotationEffect.Angle = elapsedTime * 4;
                    contrastEffect.Contrast = (float)Math.Sin(elapsedTime * 2);
                return contrastEffect;

    Then I draw the image:

            private void Canvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args)
                var size = sender.Size;
                var ds = args.DrawingSession;
                // Animate and then display the current image effect.
                ds.DrawImage(effect, (size.ToVector2() - currentEffectSize) / 2);

    It does looks like both the effect is working. All the above code is from the Official sample. 

    You could refer the scenario- "Effects" of the sample for more information and detailed code.

    Best regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, September 23, 2019 6:52 AM