1

This is quite hard for me to explain so I'll use an image as example: enter image description here
I have defined a StreamGeometry (in code).
When it is drawn with DrawingContext.DrawGeometry using both Brush to fill and Pen to stroke, the geometry is 'widened' by the Pen Thickness.
Now I'm trying to find if there is a function in WPF that can return this solid widened geometry (in any Geometry format).

So far I tried Geometry.GetWidenedPathGeometry but that only returns geometry that 'outlines' the border Pen stroke. It has a hole where the fill should be.

I guess I can use GetWidenedPathGeometry and do some sort of Union with the original geometry, 'filling' the hole. I just want to be sure there isn't an easier or more effective (faster) way.
Also it would be preferable if the geometry can stay a StreamGeometry, but GetWidenedPathGeometry converts it into (somehow mangled ?) PathGeometry.

Thanks for any advice

Riva
  • 637
  • 6
  • 14
  • 1
    You're right. You'll have to [combine](http://msdn.microsoft.com/en-us/library/ms607449.aspx) the result of GetWidenedPathGeometry with the original one. – Clemens May 29 '14 at 06:38
  • [This](http://www.charlespetzold.com/blog/2008/04/Rounded-Graphics-in-WPF.html) might also be very helpful. – Clemens May 29 '14 at 06:58

1 Answers1

1

It seems the resulting geometry from GetWidenedPathGeometry contains two figures, one for inner and another for the outer contours.

What if you removed the inner one?

There is a similar scenario at Charles Petzold Book Blog: http://www.charlespetzold.com/blog/2008/04/Rounded-Graphics-in-WPF.html

Hope it helps.

Igor.

Igor Kondrasovas
  • 1,479
  • 4
  • 19
  • 36
  • Well yes, I found out that the result contained two figures, one of which describes the inner geometry and can be deleted. A problem is that I didn't find any specification that would assure this is always the case for any geometry shape. Also Charles Petzold's 'detection' of which Figure is the inner one is imho quite funky and maybe works for his one specific simple triangle example, but I wouldn't depend on it with arbitrary shapes. In short: No, the solution isn't this simple. – Riva Oct 20 '14 at 07:07
  • I should add that I resolved this by just writing my own Trace function. Mainly because the WPF's GetWidenedPathGeometry is quite slow, atop of being 'unpredictable'. Though that's not a solution for this problem I would generally recommend. – Riva Oct 20 '14 at 07:10
  • 1
    In the particular case I had recently, I used the area of both outlined geometries to determine the inner one (smaller area). Maybe this can help you too.. – Igor Kondrasovas Dec 09 '14 at 10:34
  • @Riva Care to share your trace code? Could be quite helpful for all. – Todd Main Sep 21 '17 at 23:26