/// <summary> /// Found on Google Groups when searching for "Region.Union" while looking /// for bugs: /// --- /// Hello, /// /// I did not run your code, but I know Region.Union is flawed in both 1.0 and /// 1.1, so I assume it is in the gdi+ unmanged code dll. The best workaround, /// in terms of speed, is to use a PdnGraphicsPath, but it must be a path with /// FillMode = FillMode.Winding. You add the rectangles to the path, then you do /// union onto an empty region with the path. The important point is to do only /// one union call on a given empty region. We created a "super region" object /// to hide all these bugs and optimize clipping operations. In fact, it is much /// faster to use the path than to call Region.Union for each rectangle. /// /// Too bad about Region.Union. A lot of people will hit this bug, as it is /// essential in high-performance animation. /// /// Regards, /// Frank Hileman /// Prodige Software Corporation /// --- /// </summary> /// <param name="rectsF"></param> /// <param name="startIndex"></param> /// <param name="length"></param> /// <returns></returns> public static PdnRegion RectanglesToRegion(RectangleF[] rectsF, int startIndex, int length) { PdnRegion region; if (rectsF == null || rectsF.Length == 0 || length == 0) { region = PdnRegion.CreateEmpty(); } else { using (PdnGraphicsPath path = new PdnGraphicsPath()) { path.FillMode = FillMode.Winding; if (startIndex == 0 && length == rectsF.Length) { path.AddRectangles(rectsF); } else { for (int i = startIndex; i < startIndex + length; ++i) { path.AddRectangle(rectsF[i]); } } region = new PdnRegion(path); } } return region; }