Groups | Blog | Home
all groups > dotnet drawing api > february 2008 >

dotnet drawing api : Graphics.FillPath and Overlap Regions


Tim
2/13/2008 9:03:11 AM
Hello,

This may be a simple question. I'm trying to draw a path with multiple
polygons and circles. Transparency is set to 50%. I want the overlap
regions NOT to show. That is, they should be the same transparency level and
color as the non-overlap regions. Is there any way to do this? I keep
getting situations where the overlaps are darker, or not displayed at all.
Below is some sample code.

Color c = Color.FromArgb(50, Color.Blue);
SolidBrush b = new SolidBrush(c);
Point[] polygon = new Point[3]
{
new Point(50,50),
new Point(50,200),
new Point(150,150),
}
GraphicsPath path = new GraphicsPath();
path.addEllipse(new Rectangle(100,100,100,100));
path.addPolygon(polygon);
g.FillPath(b, path);

This code draws the polygon and the circle, but the overlapped region is not
drawn. If I draw two paths, then the overlap region is too dark. I've also
tried setting the FillMode to Winding, but that only helps if all my shapes
are circles.

Bob Powell [MVP]
2/15/2008 8:51:55 AM
The only way to do this is to use separate regions and split the
overlapping parts out by getting the union of the two regions.

when you have regions that represent both the overlapping and
non-overlapping parts you can paint each of them separately in the
transparency level you desire.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





[quoted text, click to view]
AddThis Social Bookmark Button