【问题标题】:Blurry LineGeometry in WPFWPF中的模糊线几何
【发布时间】:2014-03-27 21:14:32
【问题描述】:

我正在使用下面的代码来绘制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>

这是我得到的结果:

【问题讨论】:

  • @HenkHolterman 我更新了这个问题。左边的线条很模糊。
  • 尝试在您的窗口上设置UseLayoutRounding="True"
  • @DanBryant 没有帮助。它使所有的线条都变得模糊。
  • 您之前的问题没有解决这个问题吗? stackoverflow.com/questions/22539408/…
  • WPF 的设计假设今天这不会成为问题。很遗憾这没有发生,似乎只有喜欢访问当地 Apple Store 的程序员才会花钱购买他们需要的硬件。 WPF 将永远被贴上“廉价”的标签。因为它看起来就是这样,没有人看到真正的问题。

标签: c# wpf


【解决方案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;

结果

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-20
    • 2014-06-13
    • 2015-12-17
    • 1970-01-01
    • 1970-01-01
    • 2011-08-04
    • 2014-05-21
    • 2015-11-14
    相关资源
    最近更新 更多