如何在CanvasGeometry上添加效果

时间:2018-08-30 14:59:12

标签: uwp graphics2d win2d windows-composition-api

在我看来,Win2D中可用的所有效果都是用于绘制图像的。

CanvasGeometry呢?如何使用发光效果绘制CanvasGeometry

谢谢。

1 个答案:

答案 0 :(得分:1)

Geometry对象提供了一种绘制和操纵几何形状的方法。它具有CreatePolygonCreatePath方法可用于创建几何形状。

有关发光效果,您可以参考此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);
     }
}