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