WPF中的模糊线几何

时间:2014-03-27 21:14:32

标签: c# wpf

我使用下面的代码绘制LineGeometry个对象。但不知怎的,我变得模糊不清。知道为什么会这样吗?

public Window1()
{
    InitializeComponent();

    var x = 0;
    var y = 0;
    var n = 0;

    while (n<1000)
    {
        x = x + 20;
        if (x > 1200)
        {
            x = 0;
            y = y + 20;
        }

        var l = new LineGeometry
        {
            StartPoint = new Point(x, y),
            EndPoint = new Point(x, y + 15)
        };
        MyGroup.Children.Add(l);

        n++;
    }

}


<Canvas x:Name="MyCanvas" Width="1200" Height="700">
        <Path x:Name="MyPath" Stroke="Wheat" SnapsToDevicePixels="True">
            <Path.Data>
                <GeometryGroup x:Name="MyGroup" >

                </GeometryGroup>
            </Path.Data>

        </Path>
</Canvas>

以下是我得到的结果: enter image description here

1 个答案:

答案 0 :(得分:1)

以下是我找到的解决方案:

<强> XAML

<Window x:Class="LearnDrawing.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="700" Width="1200" Background="Black">
    <Grid>
        <Grid Width="1200" Height="700">
            <Path x:Name="MyPath">
                <Path.Data>
                    <GeometryGroup x:Name="MyGroup">
                    </GeometryGroup>
                </Path.Data>
            </Path>
        </Grid>
    </Grid>
</Window>

代码背后

var x = 0;
var y = 0;
var n = 0;
while (n < 1000)
{
    x = x + 20;
    if (x > 600)
    {
        x = 0;
        y = y + 20;
    }
    var myLineGeometry = new LineGeometry
    {
        StartPoint = new Point(x, y),
        EndPoint = new Point(x, y + 15)
    };

    MyGroup.Children.Add(myLineGeometry);
    n++;
}

MyPath.Stroke = Brushes.White;
MyPath.SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Aliased);
MyPath.Data = MyGroup;

<强>结果

enter image description here