Reputation: 2845
How do you Clip a System.Drawing.Drawing2D.GraphicsPath
with another GraphicsPath
to get a new GraphicsPath?
Note 1: It is possible to SetClip() a whole System.Drawing.Graphics
object, but what is needed here is some sort of Intersecting a GraphicsPath to get another GraphicsPath.
Note 2: The method discussed here (Intersecting GraphicsPath objects) returns a region. Here we expect a GraphicsPath
Upvotes: 1
Views: 2251
Reputation: 11617
I had a quick go at this, and the closest I got was this:
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);
}
The problem with this is that GetRegionScans()
gives you thousands of rectangles back, not just the distinct points of the lines. Uncomment the DrawPath method to see what I mean.
There is an open source library for manageing clipping, which seems to be reasonably active here (Found via this Stackoverflow question).
I have no experience with it, but it looks to be able to do what you are after.
Upvotes: 1