Ejemplo n.º 1
0
        public static GeometryRegion RectanglesToRegion(Rectangle[] rects, int startIndex, int length)
        {
            GeometryRegion region;

            if (length == 0)
            {
                region = GeometryRegion.CreateEmpty();
            }
            else
            {
                using (var path = new GeometryGraphicsPath())
                {
                    path.FillMode = FillMode.Winding;
                    if (startIndex == 0 && length == rects.Length)
                    {
                        path.AddRectangles(rects);
                    }
                    else
                    {
                        for (int i = startIndex; i < startIndex + length; ++i)
                        {
                            path.AddRectangle(rects[i]);
                        }
                    }

                    region = new GeometryRegion(path);
                    path.Dispose();
                }
            }

            return(region);
        }
Ejemplo n.º 2
0
        public static GeometryRegion RectanglesToRegion(RectangleF[] rectsF1, RectangleF[] rectsF2,
                                                        params RectangleF[][] rectsFA)
        {
            using (var path = new GeometryGraphicsPath())
            {
                path.FillMode = FillMode.Winding;

                if (rectsF1 != null && rectsF1.Length > 0)
                {
                    path.AddRectangles(rectsF1);
                }

                if (rectsF2 != null && rectsF2.Length > 0)
                {
                    path.AddRectangles(rectsF2);
                }

                foreach (RectangleF[] rectsF in rectsFA)
                {
                    if (rectsF != null && rectsF.Length > 0)
                    {
                        path.AddRectangles(rectsF);
                    }
                }

                return(new GeometryRegion(path));
            }
        }