用另一个GraphicsPath剪切GraphicsPath

本文关键字:GraphicsPath 剪切 另一个 | 更新日期: 2023-09-27 18:07:02

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

注1:这是可能的SetClip()一个完整的System.Drawing.Graphics对象,但这里需要的是某种形式的相交GraphicsPath获得另一个GraphicsPath。

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

用另一个GraphicsPath剪切GraphicsPath

我做了一个快速的尝试,我得到的最接近的是:

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方法的注释来理解我的意思。

有一个用于管理剪贴的开源库,它似乎在这里相当活跃(通过这个Stackoverflow问题找到)。

我没有经验,但它看起来能做你想要的。