How to verify if a Rectangle is completely contained in a region or graphicspath

StackOverflow https://stackoverflow.com/questions/20993621

  •  25-09-2022
  •  | 
  •  

문제

We are using GDI+ and we have different regions or graphicspath. How to determine if a rectangle is completely inside this region.

도움이 되었습니까?

해결책

The following function returns whether or not the union of region r and rectangle r1 is equal to r. Theoretically it is the same as determining whether r completely contains r1. Also, it requires a Graphics object to perform the comparison.

bool Contains(Region r, RectangleF r1, Graphics g) {
  Region u = r.Clone();
  u.Union(r1);
  return r.Equals(u, g);
}

Update: Corrected region comparison as discussed in another post

다른 팁

I Guess,

  1. Take regions or graphics path pixels to array
  2. Take Rectangle pixels to another array
  3. check each rectangle pixels from array with region pixel array
  4. if all rectangle pixels exists in region pixel array, it means rectangle contained in region
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top