本文介绍了纲要与GDI + .NET中的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个人如何介绍了使用GDI +一个GraphicsPath的?例如,我添加了两个相交的矩形到GraphicsPath的。我想提请由此产生的GraphicsPath的轮廓而已。

How does one outline a graphicspath using GDI+? For example, I add two intersecting rectangles to a GraphicsPath. I want to draw the outline of this resulting graphicspath only.

请注意,我不希望填充的区域,我只是想画出轮廓。

Note that I don't want to fill the area, I just want to draw the outline.

例:

Example:

推荐答案

有没有管理办法做到的轮廓。但是,GDI +确实有所谓的GdipWindingModeOutline的功能,可以做的正是这一点。这里是MSDN参考这code的伎俩:

There is no managed way to do the outline. However, GDI+ does have an function called GdipWindingModeOutline that can do exactly this.Here is the MSDN referenceThis code does the trick:

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

这篇关于纲要与GDI + .NET中的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 02:38