1

I'm using the code below to draw LineGeometry objects. But somehow I'm getting blurry lines. Any idea why this is happening?

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>

Here is the result I get: enter image description here

Vahid
  • 5,144
  • 13
  • 70
  • 146
  • @HenkHolterman I updated the question. The lines on the left are blurry. – Vahid Mar 27 '14 at 22:09
  • 2
    Try setting `UseLayoutRounding="True"` on your Window. – Dan Bryant Mar 27 '14 at 22:13
  • @DanBryant Didn't help. It made all of the lines blurry. – Vahid Mar 27 '14 at 22:16
  • 1
    Wasn't this resolved in your previous question? http://stackoverflow.com/questions/22539408/extra-lines-appear-when-edgemode-aliased-option-is-used-in-wpf – d.moncada Mar 27 '14 at 22:22
  • @d.moncada They look similar but here I'm adding the LineGeomtries to Path. You can test the code above. – Vahid Mar 27 '14 at 22:43
  • 2
    WPF was designed with the assumption that this would *not* be a problem today. Pretty sad that this didn't happen, seems that only programmers that like to visit their local Apple Store spend the money on the hardware they need. WPF will forever be labeled as "cheap". Because that's the way it looks and nobody sees the real problem. – Hans Passant Mar 27 '14 at 22:52
  • @HansPassant Sorry I didn't understand. – Vahid Mar 27 '14 at 23:03
  • http://en.wikipedia.org/wiki/Retina_Display – Hans Passant Mar 27 '14 at 23:18
  • @HansPassant Thanks. Luckily I solved this problem. – Vahid Mar 27 '14 at 23:35

1 Answers1

1

Here is the solution I found for this:

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>

Code Behind

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;

Result

enter image description here

Vahid
  • 5,144
  • 13
  • 70
  • 146