Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 用GDI+勾勒出一条路径;在.Net中_C#_.net_Gdi+ - Fatal编程技术网

C# 用GDI+勾勒出一条路径;在.Net中

C# 用GDI+勾勒出一条路径;在.Net中,c#,.net,gdi+,C#,.net,Gdi+,如何使用GDI+勾勒graphicspath?例如,我将两个相交的矩形添加到GraphicsPath。我只想画出这个图形的轮廓 请注意,我不想填充该区域,我只想绘制轮廓 例如: 我自己无法尝试,但我认为您应该使用图形的交点创建一个区域对象,然后使用API。 这是它的: 附言:如果这有效,请发布你的解决方案,我很好奇:)没有管理好的方法来做大纲。然而,GDI+确实有一个名为GdipWindingModeOutline的函数,可以完全做到这一点。 此代码实现以下功能: // Declaration

如何使用GDI+勾勒graphicspath?例如,我将两个相交的矩形添加到GraphicsPath。我只想画出这个图形的轮廓

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

例如:

我自己无法尝试,但我认为您应该使用图形的交点创建一个区域对象,然后使用API。
这是它的:


附言:如果这有效,请发布你的解决方案,我很好奇:)

没有管理好的方法来做大纲。然而,GDI+确实有一个名为GdipWindingModeOutline的函数,可以完全做到这一点。 此代码实现以下功能:

// 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);
    }
}
// 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);
    }
}