GDI+中的Region的集合关系

发布时间 2023-11-19 21:29:20作者: JohnYang819
string content="";
GraphicsPath c1 = new GraphicsPath();
c1.AddEllipse(0, 20, 50, 50);
GraphicsPath c2 = new GraphicsPath();
c2.AddEllipse(30, 20, 50, 50);
Region r1 = new Region(c1);
Region r2 = new Region(c2);
_graphics.FillRegion(Brushes.Red, r1);
_graphics.FillRegion(Brushes.Blue, r2);
Font font = new Font("Arial", 10);
switch (tag)
{
    case 0:
        content = "Complement";
        r1.Complement(r2);
        break;
    case 1:
        content = "Exclude";
        r1.Exclude(r2);
        break;
    case 2:
        content = "Intersect";
        r1.Intersect(r2);
        break;
    case 3:
        content = "Union";
        r1.Union(r2);
        break;
    case 4:
        content = "XOR";
        r1.Xor(r2);
        break;
}
_graphics.DrawString(content, font, Brushes.Beige, new Point(10, 0));
_graphics.FillRegion(Brushes.Yellow, r1);
font.Dispose();