Get a list of coordinates from System.Windows.Media.Geometry
Given a System.Windows.Media.Geometry
class instance, is there an easy way to convert this to a list of outlines and points? For example, how could I simply break this down into a list of LineSegments
for custom rendering.
FormattedText formattedText = new FormattedText( "Hello", ...);
Geometry textGeometry = formattedText.BuildGeometry(new System.Windows.Point(0, 0));
How to list each of the outlines (where O would be an inside/outside circle) and each of the points on each outline?
As per the answer below;
var flatten = textGeometry.GetFlattenedPa开发者_StackOverflow中文版thGeometry();
PathFigureCollection pfc = flatten.Figures;
foreach (PathFigure pf in pfc)
{
foreach (PathSegment ps in pf.Segments)
{
if (ps is LineSegment)
On the Geometry
class, you can use GetFlattenedPathGeometry()
, GetOutlinedPathGeometry()
(or related - decide what you actually want) to get a PathGeometry
and then query the Figures
to get a list of figures. Each of these PathFigure
objects has the segments (which may be line segments, bezier, etc).
Note that in doing this, you may lose some information if you do it naively - if any arbitrary Geometry can be given, you will probably need to do more than just call FlattenedPathGeometry to not lose things like fill information.
精彩评论