Search code examples
uwpgraphics2dwin2dwindows-composition-api

How to add effect on CanvasGeometry


It seems to me that all the effects available in Win2D are for drawing image.

What about CanvasGeometry? How do I draw a CanvasGeometry using, say glowing effect ?

Thanks.


Solution

  • Geometry objects provide a means of drawing and manipulating geometric shapes. It has CreatePolygon,CreatePathmethod could be used to create geometric shapes.

    For glowing effect, you could refer this code sample.

    private void DoEffect(CanvasDrawingSession ds, Size size, float amount)
    {
        size.Width = size.Width - ExpandAmount;
        size.Height = size.Height - ExpandAmount;
    
        var offset = (float)(ExpandAmount / 2);           
    
        using (var textLayout = CreateTextLayout(ds, size))
        using (var textCommandList = new CanvasCommandList(ds))
        {
            using (var textDs = textCommandList.CreateDrawingSession())
            {                     
                textDs.DrawTextLayout(textLayout, 0, 0, GlowColor);
            }
    
             glowEffectGraph.Setup(textCommandList, amount);
             ds.DrawImage(glowEffectGraph.Output, offset, offset);
    
             ds.DrawTextLayout(textLayout, offset, offset, TextColor);
         }
    }