How to compare two pf24bit images (Views: 30)
Problem/Question/Abstract: How to compare two pf24bit images Answer: 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; |