Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
给定两个 System.Drawing.Rectangle - 如何确定第二个矩形覆盖的第一个矩形面积的百分比?
例如,如果第二个矩形位于第一个矩形的一半,则结果应为 50%。
您可以使用该Rectangle.Intersect方法获取intersection矩形:
Rectangle.Intersect
intersection
Rectangle rect = new Rectangle(firstRect.Location, firstRect.Size); rect.Intersect(secondRectangle); var percentage = (rect.Width * rect.Height) * 100f/(firstRect.Width * firstRect.Height);