SRL Archive - Help and Support

A Find Bitmap in Bitmap/Debug Image?


Pure1993

2009-07-01 01:43:29

Hey guys,
Quick question: is it possible to search for a bitmap in the debug image, or in another bitmap? For example, if I create a bitmap using a TPA, can I check if that created bitmap (which will only be black and red, red for points found and black for points left out) is similar/fits into another bitmap?
Thanks,
Pure1993

Shuttleu

2009-07-01 01:45:47

im sure it would be possible
it would probably mean that you would have to scan through each pixel which can take a while so it might be best if it was created in a plugin

but yes it should be possible

~shut

bullzeye95

2009-07-01 01:58:33

function FindBitmapInBitmap(findBMP, inBMP: Integer; var x, y: Integer): Boolean;
begin
SetTargetBitmap(inBMP);
Result:= FindBitmap(findBMP, x, y);
ResetDC;
end;

function FindBitmapInDebugImg(BMP: Integer; var x, y: Integer): Boolean;
begin
SetTargetDC(GetDebugCanvas.Handle);
Result:= FindBitmap(BMP, x, y);
ResetDC;
end;
Is this what you want?

Pure1993

2009-07-01 09:34:31

From: bullzeye95
function FindBitmapInBitmap(findBMP, inBMP: Integer; var x, y: Integer): Boolean;
begin
SetTargetBitmap(inBMP);
Result:= FindBitmap(findBMP, x, y);
ResetDC;
end;

function FindBitmapInDebugImg(BMP: Integer; var x, y: Integer): Boolean;
begin
SetTargetDC(GetDebugCanvas.Handle);
Result:= FindBitmap(BMP, x, y);
ResetDC;
end;
Is this what you want?


Jup, that's what I want, thanks! :D

Pure1993

2009-07-01 17:18:33

Erm, another question: is it possible to compare two bitmap strings, without either actually being on the screen?

marpis

2009-07-01 19:36:18

From: Pure1993
Erm, another question: is it possible to compare two bitmap strings, without either actually being on the screen?


well, you can compare common pixels if the bitmaps are the same size

function CommonPixels(bmp1, bmp2: integer): integer;
var
x, y w, h: integer;
begin
GetBitmapSize(bmp1, w, h);
for x := 1 to w do
for y := 1 to h do
if FastGetPixel(bmp1, x, y) = FastGetPixel(bmp2, x, y) then
Inc(Result);
end;
(and no, i don't free bitmaps on purpose)

Pure1993

2009-07-01 20:47:12

From: marpis
well, you can compare common pixels if the bitmaps are the same size

function CommonPixels(bmp1, bmp2: integer): integer;
var
x, y w, h: integer;
begin
GetBitmapSize(bmp1, w, h);
for x := 1 to w do
for y := 1 to h do
if FastGetPixel(bmp1, x, y) = FastGetPixel(bmp2, x, y) then
Inc(Result);
end;
(and no, i don't free bitmaps on purpose)


I think you misunderstood me (sorry, my fault, not really able to say what I want to say, I'll try again ^^), I was asking if you can compare two bitmaps while they are strings… for example, how similar these two bitmaps are:

BitmapFromString(20, 14, 'beNo7enrPviNwtPfAMTg6cOg' +
'EHB06fAoZHT56Goj+MzAgq99/8DgcEdQLRPTUC9dIql6gH5H1Iqsn' +
'1V7a6QU6ckDsxa8XLe6AjkQTwRW5mHoJImrpJehInHoBo1x9EA==');

BitmapFromString(20, 14, 'beNo7enrPviNwtPfAMTg6cOg' +
'EHB06fAoZHT56Goj+MzAgq99/8DgcEdQLRPTUC9dIql6gH5H1Iqsn' +
'1V7a6QU6ckDsxa8XLe6AjkQTwRW5mHoJImrpJehInHoBo1x9EA==');

Well, these are identical, but if the second one had the same size, but looked a bit different, could you compare them without constructing them? or construct them in a way that you can compare them while using smart, without either of the bitmaps being on the SMART screen…
hope that was a better explanation… :o

bullzeye95

2009-07-01 21:41:18

function AreBitmapsIdentical(BMP1, BMP2: Integer): Boolean;
begin
Result:= BitmapToString(BMP1) = BitmapToString(BMP2);
end;

EDIT: You're right Hermen, I read too quickly.

ShowerThoughts

2009-07-02 00:50:05

I think he does mean more advanced like pixel for pixel checking.

mixster

2009-07-02 14:02:23

If you know the form of compression Freddy uses for bitmaps, you could effectively translate it to a 2D integer array by uncompressing without assigning to an image then comparing the arrays.

Otherwise, constructing them then using marpis's method or bullzeye95's earlier method (with handle collecting and setting) should work.

Gu3st...

2009-07-02 14:45:21

Marpis' method would be your best bet, but what do you mean by "not constructing a bitmap"? Do you mean without having them in the memory?

bullzeye95

2009-07-02 22:11:10

From: mixster
If you know the form of compression Freddy uses for bitmaps, you could effectively translate it to a 2D integer array by uncompressing without assigning to an image then comparing the arrays.


I believe he uses zlib, if you want to use this method.