6.4. Clipping Regions Example
Listing 6.14 uses Xor to clip regions.
Listing 6.14. Using the Xor method
Pen pen = new Pen(Color.Red, 5); SolidBrush brush = new SolidBrush(Color.Red); Rectangle rect1 = new Rectangle(50, 0, 50, 150); Rectangle rect2 = new Rectangle(0, 50, 150, 50); Region region = new Region(rect1); region.Xor(rect2); g.FillRegion(brush, region); |
Figure 6.14 shows the output from Listing 6.14.
Figure 6.14. Result of the Xor method
Now if we replace Xor with Union:
region.Union(rect2);
the new output looks like Figure 6.15.
Figure 6.15. Result of the Union method
Now let’s replace Union with Exclude:
region.Exclude(rect2); ...
Get Graphics Programming with GDI+ now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.