0

I have a Region, from which I am subtracting n number of Rectangles, now I need to get all the remaining space in terms of rectangles. Is there a way of doing it?

Thanks

1 Answers1

1

First you should realize that any set of rectangles you get may be an approximation if the region contains any curves.

Second, try calling GetRegionScans with an indentity matrix.

RectangleF[] rects = region.GetRegionScans(new Matrix());
Rotem
  • 21,452
  • 6
  • 62
  • 109
  • Thanks. It worked. Is it possible to get the rectangles in smallest possible form? – user2250447 Jun 02 '13 at 12:15
  • Actually, it is returning the rectangles horizontally, if I can get rectangles vertically in another pass should do the trick. Any ideas? – user2250447 Jun 02 '13 at 12:28
  • Rotate the region 90 degrees, get the scan rects, and then rotate back. – Rotem Jun 02 '13 at 12:29
  • Then I have to rotate back the scanned rectangles individually right? – user2250447 Jun 02 '13 at 13:01
  • Yes, using a rotation matrix with an opposite angle. – Rotem Jun 02 '13 at 13:13
  • Thanks. Is there a way to rotate rectangles without using Graphics? The only way I found to do it is using g.RotateTransform which doesn't return the coordinate of the rectangle. – user2250447 Jun 02 '13 at 13:43
  • You could write your own matrix but that would be redundant. Just add an extension method on `Matrix` that transforms a `RectangleF`. – Rotem Jun 02 '13 at 13:49