如何使用GDI +概述图形路径?例如,我将两个相交的矩形添加到GraphicsPath.我想仅绘制此结果图形路径的轮廓.
请注意,我不想填充该区域,我只想绘制轮廓.
例:

Dod*_*bit 10
没有可管理的方式来做大纲.但是,GDI +确实有一个名为GdipWindingModeOutline的函数可以做到这一点. 这是MSDN参考 这段代码可以解决问题:
// 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);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3903 次 |
| 最近记录: |