[英]Outline a path with GDI+ in .Net
如何使用GDI +概述圖形路徑? 例如,我將兩個相交的矩形添加到GraphicsPath。 我想僅繪制此結果圖形路徑的輪廓。
請注意,我不想填充該區域,我只想繪制輪廓。
例:
沒有可管理的方式來做大綱。 但是,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);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.