【问题标题】:Conversion System.Windows.Media.Geometry --> System.Drawing.Region转换 System.Windows.Media.Geometry --> System.Drawing.Region
【发布时间】:2016-01-01 13:57:49
【问题描述】:

我有一个非托管 API,它使用 System.Drawing.Region 作为参数。
问题是,我有一个System.Windows.Media.Geometry,我需要将其转换为Region-class。

我想知道我应该如何转换这种类型... 我应该寻找角点并转换它们还是已经存在转换方法[我还没有找到]


如果有人需要 System.Windows.Media.Geometry 的示例,XAML 代码如下所示:
<GeometryGroup>
    <RectangleGeometry Rect="32,0,440,89"/>
    <RectangleGeometry Rect="0,89,472,41"/>
    <RectangleGeometry Rect="472,93,66,193"/>
    <RectangleGeometry Rect="53,130,419,156"/>
    <RectangleGeometry Rect="53,184,38,102"/>
    <RectangleGeometry Rect="91,200,52,86"/>
    <RectangleGeometry Rect="143,216,75,70"/>
    <RectangleGeometry Rect="218,232,52,54"/>
    <RectangleGeometry Rect="270,248,75,38"/>
    <RectangleGeometry Rect="345,264,52,22"/>
    <RectangleGeometry Rect="516,270,22,16"/>
<GeometryGroup/>

【问题讨论】:

    标签: c# wpf xaml drawing drawing2d


    【解决方案1】:

    好的 - 我自己找到了解决方案:

    Geometry geo = .... ;
    
    IEnumerable<PolyLineSegment> segments =
        from PathFigure figure in geo.GetOutlinedPathGeometry().Figures
        from PathSegment segment in figure.Segments
        select s as PolyLineSegment;
    
    using (GraphicsPath path = new GraphicsPath())
    {
        path.StartFigure();
    
        foreach (PolyLineSegment plseg in segments)
        {
            PointF[] points = (from point in plseg.Points
                               select new Point((float)point.X, (float)point.Y)).ToArray();
    
            path.AddPolygon(points);
        }
    
        path.CloseFigure();
    
        // DO SOMETHING WITH `path´
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-25
      • 2010-11-22
      • 2019-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-22
      • 2015-08-04
      相关资源
      最近更新 更多