Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble comparing bitmaps in delphi

Status
Not open for further replies.

Vulgarian

Programmer
Mar 28, 2012
1
NZ
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.

 
Not sure, I never experience that problem (that was actually a thread of mine) but it might have to do with the size of the bitmap, as well as the pixel format. If I recall, make sure each bmp is in 24bit mode and that the size isn't abnormally large.

JD Solutions
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top