Hi there,
I 'borrowed' some code to compare two bitmaps in Delphi 6 from another thread on this site. The code is below:
function MyBitmapsAreSame(Bitmap1, Bitmap2: TBitmap): Boolean;
var
scanptr1, scanptr2: pointer;
i: integer;
PixelSize: byte;
begin
Result := false;
if (Bitmap1.Width = Bitmap2.Width) and
(Bitmap1.Height = Bitmap2.Height) and
(Bitmap1.PixelFormat = Bitmap2.PixelFormat) then
begin
PixelSize := GetPixelSize(Bitmap1.PixelFormat);
for i := 0 to (Bitmap1.Height-1) do
begin
scanptr1 := Bitmap1.ScanLine;
scanptr2 := Bitmap2.ScanLine;
Result := CompareMem(scanptr1, scanptr2, Bitmap1.Width*PixelSize);
if Result = false then break;
end;
end;
end;
When I send two bitmaps to this function that have been loaded from a file (using TBitmap.Loadfromfile) it works and does so quickly.
If I send two bitmaps which have been generated by using bitblt on other bitmaps, it does not work at all (and is slow).
Also, If I send two bitmaps which have been generated from other bitmaps using TBitmap.Canvas.Draw(x,y,bmp) it does not work at all and is slow.
I'm guessing that there's something about using canvas handles that I don't understand, but I can't find anything comprehensive on the internet to assist me.
Any help gratefully accepted. Thanks.
I 'borrowed' some code to compare two bitmaps in Delphi 6 from another thread on this site. The code is below:
function MyBitmapsAreSame(Bitmap1, Bitmap2: TBitmap): Boolean;
var
scanptr1, scanptr2: pointer;
i: integer;
PixelSize: byte;
begin
Result := false;
if (Bitmap1.Width = Bitmap2.Width) and
(Bitmap1.Height = Bitmap2.Height) and
(Bitmap1.PixelFormat = Bitmap2.PixelFormat) then
begin
PixelSize := GetPixelSize(Bitmap1.PixelFormat);
for i := 0 to (Bitmap1.Height-1) do
begin
scanptr1 := Bitmap1.ScanLine;
scanptr2 := Bitmap2.ScanLine;
Result := CompareMem(scanptr1, scanptr2, Bitmap1.Width*PixelSize);
if Result = false then break;
end;
end;
end;
When I send two bitmaps to this function that have been loaded from a file (using TBitmap.Loadfromfile) it works and does so quickly.
If I send two bitmaps which have been generated by using bitblt on other bitmaps, it does not work at all (and is slow).
Also, If I send two bitmaps which have been generated from other bitmaps using TBitmap.Canvas.Draw(x,y,bmp) it does not work at all and is slow.
I'm guessing that there's something about using canvas handles that I don't understand, but I can't find anything comprehensive on the internet to assist me.
Any help gratefully accepted. Thanks.