function TfrmScreenShot.CreateDiffBitmap(BMP1, BMP2: TBitmap; DiffColor: TColor): TBitmap;
type
TRGBQuads =
array[0..0]
of Longword;
PRGBQuads = ^TRGBQuads;
TColorConverter =
packed record
case Byte
of
0: (B: Byte;
G: Byte;
R: Byte;
Reserved: Byte);
1: (Color: TColor);
end;
var
Src1Line, Src2Line, ResultLine: PRGBQuads;
MinLines, MinColumns, MaxLines, MaxColumns: Integer;
LineIdx, ColumnIdx: Integer;
SubstColor: Longword;
Converter: TColorConverter;
begin
//TColor ist BGR, wir brauchen RGB -> umrechnen.
Converter.Color := DiffColor;
SubstColor :=
RGB(Converter.R, Converter.G, Converter.B);
//Scanline will DIBs, also machen wir zur Sicherheit mal DIBs draus.
BMP1.HandleType := bmDIB;
BMP1.HandleType := bmDIB;
BMP1.PixelFormat := pf32bit;
//Rechnen mit Wortlänge geht scheller.
BMP2.PixelFormat := pf32bit;
MaxLines := Max(BMP1.Height, BMP2.Height);
MaxColumns := Max(BMP1.Width, BMP2.Width);
MinLines := Min(BMP1.Height, BMP2.Height);
MinColumns := Min(BMP1.Width, BMP2.Width);
Result := TBitmap.Create;
try
Result.PixelFormat := pf32bit;
Result.HandleType := bmDIB;
Result.Width := MaxColumns;
Result.Height := MaxLines;
//Gleiche Pixel übernehmen, unterschiedliche durch SubstColor ersetzen.
for LineIdx := 0
to MinLines - 1
do begin
Src1Line := BMP1.ScanLine[LineIdx];
Src2Line := BMP2.ScanLine[LineIdx];
ResultLine := Result.ScanLine[LineIdx];
for ColumnIdx := 0
to MinColumns - 1
do begin
if Src1Line[ColumnIdx] = Src2Line[ColumnIdx]
then begin
ResultLine[ColumnIdx] := Src1Line[ColumnIdx];
end else begin
ResultLine[ColumnIdx] := SubstColor;
end;
end;
end;
except
Result.Free;
raise;
end;
end;