1

2つの画像が交差していることをどのように知ることができますか?

4

2 に答える 2

5

私があなたを正しくするなら

function IsIntersertButNotContained(const R1, R2: TRect): Boolean;
var
  R: TRect;

begin
// R1 and R2 intersect
  Result:= IntersectRect(R, R1, R2)
//   R1 is not contained within R2
    and not EqualRect(R, R1)
//   R2 is not contained within R1
    and not EqualRect(R, R2);
end;
于 2011-04-19T18:27:31.163 に答える
0

次のコードは完全なチェックを行います。

次へ:通常、ビットマップは長方形ではありません。「透明」として割り当てられた色があると仮定すると、黒(RGB(0,0,0))
と言い ます。互いの上にある2つのビットマップが、同じx/y座標に黒以外のピクセルを持っているかどうかを確認できます。

次のコードはを示しています。
私はコードをテストしていないので、マイナーな問題がそこにあるかもしれません

//This function first test the bounding rects and then goes into the pixels
//inside the overlaping rectangle.
function DoBitmapsOverlap(Bitmap1, Bitmap2: TBitmap; 
                          Bitmap2Offset: TPoint; TPColor: TColor): boolean;
var
  Rect1, Rect2: TRect;
  OverlapRect: TRect;
  x1,y1: integer;
  c1,c2: TColor;
begin
  Result:= false;
  Rect1:= Rect(0,0,Bitmap1.Width, Bitmap1.Height);
  with Bitmap2Offset do Rect2:= Rect(x,y,x+ Bitmap2.Width, y+Bitmap2.Height);
  if not(IntersectRect(OverlapRect, Rect1, Rect2)) then exit;
  for x1:= OverlapRect.Left to OverlapRect.Right do begin
    for y1:= OverlapRect.Top to OverlapRect.Bottom do begin
      c1:= Bitmap1.Canvas.Pixels[x1,y1];
      c2:= Bitmap1.Canvas.Pixels[x1-Bitmap2Offset.x, y1-Bitmap2Offset.y];
      Result:= (c1 <> TPColor) and (c2 <> TPColor);
      if Result then exit;            
    end; {for y1}
  end; {for x1}   
end;
于 2011-04-19T18:46:58.953 に答える