在.Net中概述GDI +的路径

如何使用GDI +概述图形路径? 例如,我将两个相交的矩形添加到GraphicsPath。 我想仅绘制此结果图形路径的轮廓。

请注意,我不想填充该区域,我只想绘制轮廓。

例: http://i.stack.imgur.com/IAVft.png

没有可管理的方式来做大纲。 但是,GDI +确实有一个名为GdipWindingModeOutline的函数可以做到这一点。 这是MSDN参考这段代码的function:

// Declaration required for interop [DllImport(@"gdiplus.dll")] public static extern int GdipWindingModeOutline( HandleRef path, IntPtr matrix, float flatness ); void someControl_Paint(object sender, PaintEventArgs e) { // Create a path and add some rectangles to it GraphicsPath path = new GraphicsPath(); path.AddRectangles(rectangles.ToArray()); // Create a handle that the unmanaged code requires. nativePath private unfortunately HandleRef handle = new HandleRef(path, (IntPtr)path.GetType().GetField("nativePath", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(path)); // Change path so it only contains the outline GdipWindingModeOutline(handle, IntPtr.Zero, 0.25F); using (Pen outlinePen = new Pen(Color.FromArgb(255, Color.Red), 2)) { g.DrawPath(outlinePen, path); } } 

我不能自己尝试,但我认为您应该使用形状的交叉点创建一个Region对象,然后使用FrameRgn API。
这是它的pinvoke签名 :

 [DllImport("gdi32.dll")] static extern bool FrameRgn( IntPtr hdc, IntPtr hrgn, IntPtr hbr, int nWidth, int nHeight); 

PS:请发布你的解决方案,如果这样,我很好奇:)