2010. szeptember 22., szerda

Compare two bitmaps


Problem/Question/Abstract:

How to compare two bitmaps

Answer:

If you really only need to know if they're 100% identical then there is a pretty fast way by reading the bitmaps in strings via a MemoryStream:

{ ... }
begin
  MemStream := TMemoryStream.Create;
  try
    Bmp1.SaveToStream(MemStream);
    MemStream.Position := 0;
    SetLength(S1, MemStream.Size);
    MemStream.Read(S1[1], Length(S1));
    MemStream.Clear;
    Bmp2.SaveToStream(MemStream);
    MemStream.Position := 0;
    SetLength(S2, MemStream.Size);
    MemStream.Read(S2[1], Length(S2));
  finally
    MemStream.Free;
  end;
  if S1 = S2 then
    {they are identically};
end;

Nincsenek megjegyzések:

Megjegyzés küldése