从System.Windows.Media.Geometry获取坐标列表 [英] Get a list of coordinates from System.Windows.Media.Geometry

查看:697
本文介绍了从System.Windows.Media.Geometry获取坐标列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个 System.Windows.Media.Geometry 类的实例,有没有一种简单的方法将其转换为轮廓和点的列表?例如,我怎么可以简单地将其分为定制渲染 LineSegments 的列表。

  FormattedText formattedText =新FormattedText(你好,...); 
几何textGeometry = formattedText.BuildGeometry(新System.Windows.Point(0,0));



如何列出每个轮廓(其中O是一个内/外圆圈)和每个每个轮廓点



由于每回答以下;

 变种弄平= textGeometry.GetFlattenedPathGeometry(); 
PathFigureCollection PFC = flatten.Figures;

的foreach(PF的PathFigure在PFC)
{
的foreach(在pf.Segments PathSegment PS)
{
如果(PS是线段)


解决方案

几何类,可以使用 GetFlattenedPathGeometry() GetOutlinedPathGeometry()(或相关的 - 决定你真正想要的)来获取的PathGeometry ,然后查询来获得数字列表。每个这些的PathFigure 对象具有片段(其可以是线段,贝塞尔等)。



注意在做这个,如果你这样做天真的可能会丢失一些信息 - 如果任意几何可以给,你可能需要做的不仅仅是打电话FlattenedPathGeometry不丢失之类的东西填写信息


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.GetFlattenedPathGeometry();
    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.

这篇关于从System.Windows.Media.Geometry获取坐标列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆