如何使用GDI +概述图形路径?例如,我将两个相交的矩形添加到GraphicsPath。我只想绘制此生成的Graphicspath的轮廓。
请注意,我不想填充该区域,我只想绘制轮廓。
例子:
最佳答案
没有管理大纲的方法。但是,GDI +确实有一个名为GdipWindingModeOutline的函数可以完全做到这一点。
Here is the MSDN reference
这段代码可以解决这个问题:
// 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);
}
}
关于c# - 在.Net中使用GDI +概述路径,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1592285/