Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 24th, 2005, 10:07 AM   #1
scheisskopf
Newbie
 
Join Date: Aug 2005
Posts: 9
Rep Power: 0 scheisskopf is on a distinguished road
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 )
scheisskopf is offline   Reply With Quote
Old Aug 24th, 2005, 10:13 AM   #2
Dizzutch
Professional Programmer
 
Dizzutch's Avatar
 
Join Date: Dec 2004
Location: Worcester, MA
Posts: 441
Rep Power: 4 Dizzutch is on a distinguished road
Send a message via ICQ to Dizzutch Send a message via AIM to Dizzutch Send a message via MSN to Dizzutch Send a message via Yahoo to Dizzutch
What's the error?
__________________
naked pictures of you | PFO F@H stats
Dizzutch is offline   Reply With Quote
Old Aug 24th, 2005, 10:17 AM   #3
scheisskopf
Newbie
 
Join Date: Aug 2005
Posts: 9
Rep Power: 0 scheisskopf is on a distinguished road
invalid types `unsigned char[int]' for array subscript
scheisskopf is offline   Reply With Quote
Old Aug 24th, 2005, 10:21 AM   #4
Dizzutch
Professional Programmer
 
Dizzutch's Avatar
 
Join Date: Dec 2004
Location: Worcester, MA
Posts: 441
Rep Power: 4 Dizzutch is on a distinguished road
Send a message via ICQ to Dizzutch Send a message via AIM to Dizzutch Send a message via MSN to Dizzutch Send a message via Yahoo to Dizzutch
looks like you need to typecast your variables before sending them into memcmp.
__________________
naked pictures of you | PFO F@H stats
Dizzutch is offline   Reply With Quote
Old Aug 24th, 2005, 10:23 AM   #5
scheisskopf
Newbie
 
Join Date: Aug 2005
Posts: 9
Rep Power: 0 scheisskopf is on a distinguished road
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
scheisskopf is offline   Reply With Quote
Old Aug 24th, 2005, 10:27 AM   #6
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4 Polyphemus_ is on a distinguished road
if you only get compile errors, please post the complete log.
Polyphemus_ is offline   Reply With Quote
Old Aug 24th, 2005, 10:30 AM   #7
Dizzutch
Professional Programmer
 
Dizzutch's Avatar
 
Join Date: Dec 2004
Location: Worcester, MA
Posts: 441
Rep Power: 4 Dizzutch is on a distinguished road
Send a message via ICQ to Dizzutch Send a message via AIM to Dizzutch Send a message via MSN to Dizzutch Send a message via Yahoo to Dizzutch
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.
__________________
naked pictures of you | PFO F@H stats
Dizzutch is offline   Reply With Quote
Old Aug 24th, 2005, 10:30 AM   #8
scheisskopf
Newbie
 
Join Date: Aug 2005
Posts: 9
Rep Power: 0 scheisskopf is on a distinguished road
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
scheisskopf is offline   Reply With Quote
Old Aug 24th, 2005, 10:34 AM   #9
scheisskopf
Newbie
 
Join Date: Aug 2005
Posts: 9
Rep Power: 0 scheisskopf is on a distinguished road
cheers guys, REALLY appreciate it. I am sure you have been in my position when you are just starting out. Yuck.
scheisskopf is offline   Reply With Quote
Old Aug 24th, 2005, 12:34 PM   #10
Scorpions4ever
Programmer
 
Join Date: Jun 2005
Posts: 86
Rep Power: 4 Scorpions4ever is on a distinguished road
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], ...);
Scorpions4ever is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:50 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC