1

2 つの System.Drawing.Rectangle を指定すると、最初の四角形の面積の何% を 2 番目の四角形がカバーするかを判断する方法は?

たとえば、2 番目の四角形が最初の四角形の中間に配置されている場合、結果は 50% になります。

4

1 に答える 1

3

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);
于 2013-09-21T12:24:13.007 に答える