Get a list of coordinates from System.Windows.Media.Geometry

Given an instance of the System.Windows.Media.Geometry class, is there an easy way to convert it to a list of paths and points? For example, how could I just break this down into a LineSegments list for custom rendering.

 FormattedText formattedText = new FormattedText( "Hello", ...); Geometry textGeometry = formattedText.BuildGeometry(new System.Windows.Point(0, 0)); 

How to list each of the circuits (where O will be the internal / external environment) and each of the points in each circuit?

According to the answer below;

  var flatten = textGeometry.GetFlattenedPathGeometry(); PathFigureCollection pfc = flatten.Figures; foreach (PathFigure pf in pfc) { foreach (PathSegment ps in pf.Segments) { if (ps is LineSegment) 
+4
source share
1 answer

In the Geometry class, you can use GetFlattenedPathGeometry() , GetOutlinedPathGeometry() (or related, decide what you really want) to get PathGeometry , and then query Figures to get a list of numbers. Each of these PathFigure objects has segments (which can be line segments, bezier, etc.).

Note that in doing so, you may lose some information if you do it naively - if any arbitrary geometry can be provided, you will probably have to do more than just call FlattenedPathGeometry so as not to lose things like filling information .

+2
source

All Articles