【问题标题】:Clipping GraphicsPath with another GraphicsPath用另一个 GraphicsPath 裁剪 GraphicsPath
【发布时间】:2011-11-07 12:33:58
【问题描述】:

如何用另一个GraphicsPath 剪辑System.Drawing.Drawing2D.GraphicsPath 以获得新的GraphicsPath

注意 1:可以 SetClip() 整个 System.Drawing.Graphics 对象,但这里需要某种与 GraphicsPath 相交以获取另一个 GraphicsPath。

注意 2:这里讨论的方法 (Intersecting GraphicsPath objects) 返回一个区域。这里我们期望一个 GraphicsPath

【问题讨论】:

    标签: c# gdi+ gdi


    【解决方案1】:

    我对此进行了快速了解,我得到的最接近的是:

    var region = new Region(gp1);
    region.Intersect(gp2);
    
    var gpResult = new GraphicsPath();
    gpResult.AddRectangles(region.GetRegionScans(new Matrix()));
    gpResult.CloseAllFigures();
    
    using (var br = new SolidBrush(Color.LightYellow))
    {
        e.Graphics.FillPath(br, gpResult);
        //e.Graphics.DrawPath(Pens.Black, gpResult);
    }
    

    问题在于GetRegionScans() 会返回数千个矩形,而不仅仅是线条的不同点。取消注释 DrawPath 方法以了解我的意思。

    有一个用于管理剪辑的开源库,它似乎相当活跃here(通过this Stackoverflow question 找到)。

    我没有这方面的经验,但它看起来可以做你想要的。

    【讨论】:

    • 我更喜欢外部库。来自其演示的代码是解决方案:Polygons solution2 = new Polygons();剪裁器 c = new Clipper(); c.UseFullCoordinateRange = false; c.AddPolygons(subjects, PolyType.ptSubject); c.AddPolygons(剪辑, PolyType.ptClip); exSolution.Clear();解决方案。清除(); c.Execute(GetClipType(), 解决方案, GetPolyFillType(), GetPolyFillType());
    猜你喜欢
    • 2014-08-02
    • 1970-01-01
    • 2012-11-09
    • 2010-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多