Notice Of Closure

Please note that this website is due to close down on 15th June 2020.

In the interim I will try to move as much content as possible over to my GitHub account. Thanks to everyone who has supported the site over the years.

» Help

How to compare two pf24bit images

   

The code below compares two pf24bit images and tells you if they are alike or not. It also gives you the lines and pixels that are different:

function Tbilde_form.CompareBitmaps(B1, B2: TBitmap): boolean;
var
  ps1, pr1, ps, pr: PRGBTriple;
  I, J, Bps: Integer;
  tid: TDateTime;

  function BytesPerScanline(PixelsPerScanline, BitsPerPixel,
    Alignment: Longint): Longint;
  begin
    Dec(Alignment);
    Result := ((PixelsPerScanline * BitsPerPixel) + Alignment)
      and not Alignment;
    Result := Result div 8;
  end;

begin
  tid := now;
  Result := True;
  ps1 := b1.ScanLine [0];
  pr1 := b2.ScanLine [0];
  Bps := BytesPerScanLine(b1.Width, 24, 32);
  for I := 0 to b1.Height - 1 do
  begin
    ps := PRGBTriple (PChar (ps1) - Bps * I);
    pr := PRGBTriple (PChar (pr1) - Bps * I);
    for J := 0 to b1.Width - 1 do
    begin
      if not CompareMem(Pr, Ps, SizeOf(TRGBTriple)) then
      begin
        memo1.lines.Add('Line:' + inttostr(I) + ' point: ' + inttostr(j));
        Result := False;
       {Break}
      end;
      Inc (pr);
      Inc (ps)
    end;
    {if not Result then Break}
  end;
  tid_label.caption := timetostr(now - tid);
end;
Original resource: The Delphi Pool
Author: Paul Loht & Bernt Wold
Added: 2009-11-06
Last updated: 2009-11-06

« Return to contents »