有没有比逐像素检查它们更好的方法?
解决方法
您可以将两个位图保存到TMemoryStream并使用CompareMem进行比较:
@H_403_6@function IsSameBitmap(Bitmap1,Bitmap2: TBitmap): Boolean;
var
Stream1,Stream2: TMemoryStream;
begin
Assert((Bitmap1 <> nil) and (Bitmap2 <> nil),'Params can''t be nil');
Result:= False;
if (Bitmap1.Height <> Bitmap2.Height) or (Bitmap1.Width <> Bitmap2.Width) then
Exit;
Stream1:= TMemoryStream.Create;
try
Bitmap1.SaveToStream(Stream1);
Stream2:= TMemoryStream.Create;
try
Bitmap2.SaveToStream(Stream2);
if Stream1.Size = Stream2.Size Then
Result:= CompareMem(Stream1.Memory,Stream2.Memory,Stream1.Size);
finally
Stream2.Free;
end;
finally
Stream1.Free;
end;
end;
begin
if IsSameBitmap(MyImage1.Picture.Bitmap,MyImage2.Picture.Bitmap) then
begin
// your code for same bitmap
end;
end;
我没有对此代码X扫描线进行基准测试,如果您这样做,请告诉我们哪一个是最快的.