Conversion System.Windows.Media.Geometry --> System.Drawing.Region

I have an unmanaged API, which uses a System.Drawing.Region as argument. The problem is, that I have a System.Windows.Media.Geometry, which I need to convert into the Region-class.

I wonder how I should convert this type... Should I look for corner points and convert them or does already a conversion method exist [which I did not yet find]?

If someone needs an example for a System.Windows.Media.Geometry, the XAML-code looks as following:

    <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"/>


Ok - I found the solution by myself:

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())

    foreach (PolyLineSegment plseg in segments)
        PointF[] points = (from point in plseg.Points
                           select new Point((float)point.X, (float)point.Y)).ToArray();



    // DO SOMETHING WITH `path´

Need Your Help

Getting user id for facebook

android facebook access-token userid

I am working on an Android Application. A part of this application is to login on Facebook. I can get the access tokens.I am populating my database and want the Facebook user id to be the PID for e...

Why JS function name conflicts with element ID?

javascript html

I've got two almost identical simple JS fiddles calling a function on select change. Function name is the same as select ID in both cases, but for some reason the first fiddle works just fine, and ...