Quipex

Untitled

Jan 28th, 2016
437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.88 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, StdCtrls, ExtCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     GroupBox1: TGroupBox;
  12.     Button1: TButton;
  13.     Image1: TImage;
  14.     Timer1: TTimer;
  15.     procedure Button1Click(Sender: TObject);
  16.     procedure Timer1Timer(Sender: TObject);
  17.   private
  18.     { Private declarations }
  19.   public
  20.     { Public declarations }
  21.   end;
  22.  
  23. var
  24.   Form1: TForm1;
  25.  
  26. implementation
  27.  
  28. {$R *.dfm}
  29.  
  30. procedure TForm1.Button1Click(Sender: TObject);
  31.  
  32. begin
  33.   if timer1.Enabled=true then
  34.     timer1.Enabled:=false
  35.   else
  36.     timer1.Enabled:=true;
  37. end;
  38.  
  39. procedure TForm1.Timer1Timer(Sender: TObject);
  40. var
  41.   bmp:TBitmap;
  42.   scrn, space:TImage;
  43. begin
  44.   bmp:=Tbitmap.Create;
  45.   bmp.Width:=150;
  46.   bmp.Height:=64;
  47.   BitBlt(bmp.Canvas.Handle, 0, 0, screen.width, screen.Height, GetDC(0), (screen.width div 2)-73, 225, SRCCOPY);
  48.   image1.picture.Assign(bmp);
  49.   bmp.SaveToFile('1.png');
  50.   scrn.LoadFromFile('1.png');
  51.   space.LoadFromFile('space.png');
  52.   CompareImages(scrn, space);
  53. end;
  54.  
  55.  
  56. procedure CompareImages(Image1, Image2: TImage);
  57. var x, y: integer;
  58.    differences: LongInt;
  59.    line1, line2: PByteArray;
  60.    procent: single;
  61. const  porog=5;
  62. begin
  63.    differences:=0;
  64.    for y:=0 to Image1.Picture.Bitmap.Height - 1 do begin
  65.      line1:=Image1.Picture.Bitmap.ScanLine[y];
  66.      line2:=Image2.Picture.Bitmap.ScanLine[y];
  67.      for x:=0 to Image1.Picture.Bitmap.Width - 1 do
  68.        if abs(line1[x] - line2[x]) > porog then
  69.          inc(differences);
  70.      if Image1.Picture.Bitmap.Height*Image1.Picture.Bitmap.Width>0 then
  71.        procent:=100*(differences/(Image1.Picture.Bitmap.Height*
  72.        Image1.Picture.Bitmap.Width))
  73.      else
  74.        procent:=0;
  75.      if procent>50 then
  76.      begin
  77.       showmessage('rabotaet');
  78.       Ttimer1.enable:=false;
  79.      end;
  80.    end;
  81. end;
  82.  
  83. end.
Advertisement