All pastes #19509 Raw Edit

Someone

public text v1 · immutable
#19509 ·published 2005-08-07 17:30 UTC
rendered paste body
function GetCanvas:TCanvas;
begin
  result:= TCanvas.Create;
  result.Handle := GetWindowDC(Window);
end;

function ColorRGB(SColor, i: Integer): Extended;
var
  Color: TColor;
begin
  Color := ColorToRGB(SColor);
  Result:= 0;
  case i of
    1:result:= GetRValue(Color);
    2:result:= GetGValue(Color);
    3:result:= GetBValue(Color);
  end;
end;

function SimilarColors(Color1, Color2, Tolerance: Integer): Boolean;
begin
  Result:=False;
  if(Abs(Round(ColorRGB(Color1, 1))-Round(ColorRGB(Color2, 1)))<=Tolerance)then
  begin
    if(Abs(Round(ColorRGB(Color1, 2))-Round(ColorRGB(Color2, 2)))<=Tolerance)then
    begin
      if(Abs(Round(ColorRGB(Color1, 3))-Round(ColorRGB(Color2, 3)))<=Tolerance)then
        begin
          Result:= True;
        end;
    end;
  end;
end;



function MaskOn(mask, source: TBitmap; var x: Integer; Tolerance: Integer):TBitmap;
var
  cx, cy, rc: Integer;
begin
  rc:=0;
  Result:= TBitmap.Create;
  for cy:= 0 to mask.Height-1 do
    for cx:= 0 to mask.Width-1 do
    if(mask.Canvas.Pixels[cx, cy]<>0)then
      Mask.Canvas.Pixels[cx, cy]:= Source.Canvas.Pixels[cx, cy];
    result:=Mask;
  for cy:= 0 to mask.Height-1 do
    for cx:= 0 to mask.Width-1 do
    if(Mask.Canvas.Pixels[cx, cy]<>0)then
      if(rc=0)then
        rc:= Mask.Canvas.Pixels[cx, cy]
      else
      if not(SimilarColors(Mask.Canvas.Pixels[cx, cy], rc, Tolerance))then
      begin
        ShowMessage('Exiting') ;
        Exit;
      end;
      x:= x + mask.Width;
end;


procedure TfrmMacro.Button1Click(Sender: TObject);
var
x, y: Integer;
Rect, Rect2: TRect;
begin
  Exis := TBitmap.Create;
  BitBlt(Exis.Canvas.Handle, 0, 0, 15, 15, GetWindowDC(Window), 9, 9, SRCCOPY);
  ImgCanvas.Picture.Bitmap:= Exis;
  imgCanvas.Picture.Bitmap:= MaskOn(imgCanvas.Picture.Bitmap, Exis, x, 2);
end;