0

There is a good discussion about getting a widened path geometry on this thread:

Create a polygon around a polyline like a buffer

In my case, I would like to have the resulting outer line not "rounded", but totally flat. Is that Possible?

I tried to change line joins property, but there is no change on the resulting visual.

Here is the code to reproduce the problem:

private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        StreamGeometry geom = new StreamGeometry();

        DrawLines(geom);

        Pen p = new Pen(Brushes.Black, 10);
        p.LineJoin = PenLineJoin.Miter;
        p.EndLineCap = PenLineCap.Flat;    
        p.StartLineCap = PenLineCap.Flat;

        PathGeometry pathGeoWidened = geom.GetWidenedPathGeometry(p);
        PathGeometry pathGeom = pathGeoWidened.GetOutlinedPathGeometry();

        Path myPath = new Path();
        myPath.Stroke = Brushes.Black;
        myPath.Data = pathGeom;
        myCanvas.Children.Add(myPath);

    }

    private static void DrawLines(StreamGeometry geom)
    {
        using (var context = geom.Open())
        {
            context.BeginFigure(new Point(100, 100), true, true);
            context.LineTo(new Point(100, 200), true, true);
            context.LineTo(new Point(200, 200), true, true);
            context.LineTo(new Point(200, 100), true, true);
        }
    }

Any thoughts?

Igor.

Community
  • 1
  • 1
Igor Kondrasovas
  • 1,479
  • 4
  • 19
  • 36
  • Can you not draw same polygon with `ScaleTransform` as `RenderTransform`? – dkozl Oct 18 '14 at 09:36
  • http://stackoverflow.com/questions/22905589/path-geometry-clipping-equvalent-in-winrt/23028091#23028091 and http://stackoverflow.com/questions/23151297/wpf-path-how-to-draw-this-in-xaml/23152512#23152512 – Shivam cv Oct 18 '14 at 09:46
  • not sure how exactly it looks (so that it's called *totally flat*)? – King King Oct 18 '14 at 10:36
  • I added a sample code in the original thread. Unfortunately I still cannot post images, but this is easy to reproduce. No matter what I do in the pen line joins or even at the Path line joins, the result is always the same. – Igor Kondrasovas Oct 20 '14 at 10:00
  • dkozl, regarding ScaleTransform, can I apply a ScaleTransform directly over a StreamGeometry object? I don't need scale only for rendering, but I need to retrieve the actual vertexes and point positions of the resulting contours. – Igor Kondrasovas Oct 20 '14 at 10:15
  • 1
    I got some help and seems I can manage the issue, changing the LineTo isSmoothJoin parameter to false. Thank you guys! – Igor Kondrasovas Oct 20 '14 at 10:16
  • Original answer: https://social.msdn.microsoft.com/Forums/en-US/85f644af-a1ba-4590-86f4-6b4016a026bd/getwidenedpathgeometry-with-flat-pen-stills-rounds-outter-countour – Nick Jun 22 '15 at 14:46

1 Answers1

0

Use a PathGeometry instead of a StreamGeometry. For some reason StreamGeometry always has round line joins.

Joey
  • 344,408
  • 85
  • 689
  • 683