All pastes #20587 Raw Edit

Someone

public text v1 · immutable
#20587 ·published 2005-08-20 23:27 UTC
rendered paste body
function FindBitmap(c: TBitmap; var x, y: Integer; xn, yn, xs, ys, Tol: Integer): Boolean;
var
  cx, cy, cx2, cy2, i: Integer;
  Bmp: TBitmap;
  BrokeMe: Boolean;
  Line, cLine: PRGB32Array;
  Size: TRect;
begin
  i := 0;
  Result:= False;
  BrokeMe:= False;
  bmp:= TBitmap.Create;
  GetWindowRect(Window, Size);
  bmp.Width:= Size.Right - Size.Left;
  bmp.Height:= Size.Bottom - Size.Top;
  BitBlt(bmp.Canvas.Handle, 0, 0, bmp.Width, bmp.Height,
                            GetWindowDC(Window), 0, 0, SRCCOPY);
  bmp.PixelFormat:= pf32bit;
  cLine:= c.ScanLine[0];
  for cy:= yn to ys do
  begin
    Line:= Bmp.ScanLine[cy];
    BrokeMe:= False;
    for cx:= xn to xs do
    if(SimilarColors(RGB(Line[cx].R, Line[cx].G, Line[cx].B), RGB(cLine[0].R, cLine[0].G, cLine[0].B), Tol))then
    begin
      for cy2:= cy to cy + c.Height - 1 do
      begin
        cLine:= c.ScanLine[cy2 - cy];
        Line:= Bmp.ScanLine[cy2];
        for cx2:= cx to cx + c.Width - 1 do
        if(SimilarColors(RGB(Line[cx2].R, Line[cx2].G, Line[cx2].B), RGB(cLine[cx2-cx].R, cLine[cx2-cx].G, cLine[cx2-cx].B), Tol))then
        begin
          i:= i + 1;
          if(i >= c.Width * c.Height)then
          begin
            x:= cx;
            y:= cy;
            Result:= True;
            Exit;
          end;
        end else
        begin
          i:= 0;
          BrokeMe:= True;
          Break;
        end;
        if(BrokeMe)then Break;
      end;
    end;
  end;
end;