Toby1
2012-08-18 16:15:57
How can I compare a bitmap to another bitmap?
2012-08-18 16:15:57
2012-08-18 16:23:48
function CalculatePixelShift(Bmp1, Bmp2: Integer; CompareBox: TBox): Integer;
^ will measure the change from 1 bitmap to another.2012-08-18 16:40:24
2012-08-18 16:42:28
From: Le Jingle
Compare as in this?^ will measure the change from 1 bitmap to another.
function CalculatePixelShift(Bmp1, Bmp2: Integer; CompareBox: TBox): Integer;
If no, more information as to what you wish to do with the bitmaps would help to aide in finding something to compare the bitmaps.
2012-08-19 03:43:30
2012-08-19 04:43:14
From: Chewar
Thank you.. I'm trying this function out atm, I wish the docs were a bit more complete. The thing is we want to compare a bitmap to a part of another bitmap (second bitmap being bigger in width and height).
2012-08-19 08:37:08
From: Wizzup?
My suggestion:
Set the larger bitmap as a target, use FindBitmapDeformedToleranceIn with the smaller bitmap in a part to see how much they match.
http://docs.villavu.com/simba/scriptref/bitmaps.html#finddeformedbitmaptolerancein
2012-08-19 08:54:19
From: Flight
Now there's a good idea. I see loading the big bitmap and setting it as the target (then finding the small bitmap within the large) is really straight forward, but how would we set our original target back after comparing the two bitmaps? Getting the original target ID and setting that ID back, that I don't know how to do.
I can see where this would lead to a similar SPS.
2012-08-19 10:42:13
Function FindBitmapInBitmap(BMP, BitmapToFind: Integer; var P: TPoint; Area: TBox; Tolerance: Integer): Boolean;
var
BmpW, BmpH, DX, DY, I, J, X, Y, W, H: Integer;
FindColours, SearchColours: T2DIntegerArray;
Label Skip;
begin
GetBitmapSize(BMP, W, H);
GetBitmapSize(BitmapToFind, BmpW, BmpH);
SearchColours := GetBitmapAreaColors(BMP, 0, 0, W, H);
FindColours := GetBitmapAreaColors(BitmapToFind, 0, 0, BmpW, BmpH);
BmpW := BmpW - 1;
BmpH := BmpH - 1;
dX := (Area.X2 - Area.X1) - BmpW;
dY := (Area.Y2 - Area.Y1) - BmpH;
For I := 0 To DY Do
For J := 0 To DX Do
begin
For Y := 0 To BmpH Do
For X := 0 To BmpW Do
begin
if (FindColours[Y][X] <> 0) then
if (Not SimilarColors(FindColours[Y][X], SearchColours[Y + I][X + J], Tolerance)) then
GoTo Skip;
end;
P := Point(J + Area.X1, I + Area.Y1);
Resul:= True;
Exit;
Skip:
continue;
end;
P(-1, -1);
Result := False;
end;
2012-08-19 10:48:11
From: Brandon
I can't get the goto to work. If you do though, this should work.
Function FindBitmapInBitmap(BMP, BitmapToFind: Integer; var P: TPoint; Area: TBox; Tolerance: Integer): Boolean;
var
BmpW, BmpH, DX, DY, I, J, X, Y, W, H: Integer;
FindColours, SearchColours: T2DIntegerArray;
Label Skip;
begin
GetBitmapSize(BMP, W, H);
GetBitmapSize(BitmapToFind, BmpW, BmpH);
SearchColours := GetBitmapAreaColors(BMP, 0, 0, W, H);
FindColours := GetBitmapAreaColors(BitmapToFind, 0, 0, BmpW, BmpH);
BmpW := BmpW - 1;
BmpH := BmpH - 1;
dX := (Area.X2 - Area.X1) - BmpW;
dY := (Area.Y2 - Area.Y1) - BmpH;
For I := 0 To DY Do
For J := 0 To DX Do
begin
For Y := 0 To BmpH Do
For X := 0 To BmpW Do
begin
if (FindColours[Y][X] <> 0) then
if (Not SimilarColors(FindColours[Y][X], SearchColours[Y + I][X + J], Tolerance)) then
GoTo Skip;
end;
P := Point(J + Area.X1, I + Area.Y1);
Resul:= True;
Exit;
Skip:
continue;
end;
P(-1, -1);
Result := False;
end;