2011-12-05 39 views
1

第一個圖像是我所擁有的 - 我用來「突出顯示」一串字符的Rectangle s的列表。第二張圖片(右圖)是我想看到的模型。刪除在矩形之間共享的線段

刪除共享線段的最佳方法是什麼?

What I have What I want

回答

0

好吧,我想我已經找到了一個體面的解決辦法。

// create a pen with a width of 2px (half of it will be blanked out so it will 
// essentially be a width of 1px) 
Pen pen = new Pen(Color.Blue, 2f); 

// build a GraphicsPath with the rectangles 
GraphicsPath gp = new GraphicsPath(); 
gp.AddRectangle(...); 
gp.AddRectangle(...); 
gp.AddRectangle(...); 

// g is our Graphics object 
// exclude the region so the path doesn't draw over it 
Region reg = new Region(gp); 
g.ExcludeClip(reg); 

// now draw path, it won't show up inside the excluded clipping region 
g.DrawPath(pen, gp); 

// clean up 
g.ResetClip(); 
pen.Dispose(); 
gp.Dispose(); 
reg.Dispose();