![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Aug 2005
Posts: 9
Rep Power: 0
![]() |
compare bitmaps
i am trying to see whether one bitmap exists inside another (which is a screen print). i am trying to use memcmp:
int main() {
HANDLE hBitMap = LoadImage(0, "img.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
BITMAP bitmap;
GetObject(hBitMap,sizeof(BITMAP),&bitmap);
int size = bitmap.bmHeight*bitmap.bmWidth*bitmap.bmBitsPixel/8;
BYTE *lpBits = new BYTE[ size ];
GetBitmapBits((HBITMAP)hBitMap,size,lpBits );
HANDLE hBitMap2 = LoadImage(0, "img2.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
BITMAP bitmap2;
GetObject(hBitMap2,sizeof(BITMAP),&bitmap2);
int size2 = bitmap2.bmHeight*bitmap2.bmWidth*bitmap2.bmBitsPixel/8;
BYTE *lpBits2 = new BYTE[ size2 ];
GetBitmapBits((HBITMAP)hBitMap2,size2,lpBits2 );
int ScreenWidth = bitmap2.bmWidth;
int ScreenHeight = bitmap2.bmHeight;
int numOfCard = 1;
int cardHeight = bitmap.bmHeight;
int card_line_length = bitmap.bmWidth;
for( int i = 0 ; i < ScreenWidth; i++ ) {
for( int j = 0 ; j < ScreenHeight; j++ ) {
for ( int k= 0; k < numOfCard; k++ ) {
int tmpY = j;
for ( int x = 0; x < cardHeight; x++ ) {
if ( memcmp(lpBits2[i][tmpY],lpBits[x], card_line_length ) != 0 )
break; // we didnt find macth of a line
tmpY++; // move to next line
}
if ( x == cardHeight) {
cout << "found";
}
}
}
}
system("PAUSE");
return 0;
}this is throwing the error at the moment: memcmp(lpBits2[i][tmpY],lpBits[x], card_line_length ) |
|
|
|
|
|
#2 |
|
Professional Programmer
|
What's the error?
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: Aug 2005
Posts: 9
Rep Power: 0
![]() |
invalid types `unsigned char[int]' for array subscript
|
|
|
|
|
|
#4 |
|
Professional Programmer
|
looks like you need to typecast your variables before sending them into memcmp.
|
|
|
|
|
|
#5 |
|
Newbie
Join Date: Aug 2005
Posts: 9
Rep Power: 0
![]() |
i havent got a clue wats going on. i am almost about to give up. could you compile that code?
i have posted everywhere on the fucking net and no ones seems to reply |
|
|
|
|
|
#6 |
|
Expert Programmer
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4
![]() |
if you only get compile errors, please post the complete log.
|
|
|
|
|
|
#7 |
|
Professional Programmer
|
i don't have access to a box with gcc right now, i can look at it tonight if it hasn't been solved yet.
|
|
|
|
|
|
#8 |
|
Newbie
Join Date: Aug 2005
Posts: 9
Rep Power: 0
![]() |
here you go:
Compiler: Default compiler Building Makefile: "C:\Documents and Settings\ftwyman.MARINEDATA\Desktop\test\Makefile.win" Executing make... make.exe -f "C:\Documents and Settings\ftwyman.MARINEDATA\Desktop\test\Makefile.win" all g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" main.cpp: In function `int main()': main.cpp:41: error: invalid types `unsigned char[int]' for array subscript make.exe: *** [main.o] Error 1 Execution terminated cheers |
|
|
|
|
|
#9 |
|
Newbie
Join Date: Aug 2005
Posts: 9
Rep Power: 0
![]() |
cheers guys, REALLY appreciate it. I am sure you have been in my position when you are just starting out. Yuck.
|
|
|
|
|
|
#10 |
|
Programmer
Join Date: Jun 2005
Posts: 86
Rep Power: 4
![]() |
Wait a sec. lpBits2 is declared as a one-dim pointer (BYTE *lpBits2). It is probably complaining that your memcmp is treating it as a 2-D array (lpBits2[i][tmpY]).
Shouldn't you just do memcmp(lpBits2[i], ...); |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|