d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Win32 Api And Windows Gdi > I Doubt This Exists
Prev14567Next
Add Reply New Topic New Poll
Member
Posts: 11,637
Joined: Feb 2 2004
Gold: 434.84
Nov 14 2009 10:48am
Quote (Muted @ Nov 14 2009 07:42am)
Quit fucking saying I have potential, that's Goddamn annoying.
I don't want a job, there's a big difference between HOBBY and JOB. This is a hobby, something like bike riding, I don't do it "professionally" even though I'm 'decent' at it, in an average sense.
No, I don't work good on teams, I never have. Guess your childhood does mold how you think and feel, and people always say people say that "for attention," how cute.

Can't you just ignore me like the rest of the people?
http://forums.d2jsp.org/topic.php?t=36343029&f=120&o=0 - There's the link, have fun. :)


You don't want to do it as a job, yet:

Quote (Muted)

but nothing really "visual" (GUIs FTW) and I guess that's fine in all but, I'm finally hitting that wall where I want to do some more "standard" stuff just so I can say I can and possibly make a portfilio to show people.
Y'know, like, try and get a job out of it, 'cause it's a really fun hobby at times


Que?
Member
Posts: 31,680
Joined: Nov 10 2007
Gold: 1.00
Nov 14 2009 11:25am
Quote (rockonkenshin @ 14 Nov 2009 11:48)
You don't want to do it as a job, yet:



Que?


Some people make me laugh when they insult me, others just seriously make me go :( and I don't know why.
Member
Posts: 11,637
Joined: Feb 2 2004
Gold: 434.84
Nov 14 2009 11:45am
Quote (Muted @ Nov 14 2009 01:25pm)
Some people make me laugh when they insult me, others just seriously make me go :( and I don't know why.


So which button have I pushed, A or B?
Member
Posts: 5,219
Joined: Oct 29 2009
Gold: 0.00
Warn: 20%
Nov 14 2009 02:30pm
Quote (Muted @ Nov 14 2009 04:42am)
Quit fucking saying I have potential, that's Goddamn annoying.
I don't want a job, there's a big difference between HOBBY and JOB. This is a hobby, something like bike riding, I don't do it "professionally" even though I'm 'decent' at it, in an average sense.
No, I don't work good on teams, I never have.Guess your childhood does mold how you think and feel, and people always say people say that "for attention,"how cute.

Can't you just ignore me like the rest of the people?
http://forums.d2jsp.org/topic.php?t=36343029&f=120&o=0 - There's the link, have fun. :)


wat

Quote (rockonkenshin @ Nov 14 2009 09:48am)
You don't want to do it as a job, yet:

Que?


Obviously, she wants us to think that she's this good (lol) at something she doesn't take seriously. Except she fails at actually being consistent.

This post was edited by infinitesimal on Nov 14 2009 02:35pm
Member
Posts: 31,680
Joined: Nov 10 2007
Gold: 1.00
Nov 14 2009 03:29pm
Quote (rockonkenshin @ 14 Nov 2009 12:45)
So which button have I pushed, A or B?


There's only one of two reasons you'd ask, and at this point, it really doesn't matter, so there's no point in lying obviously: B
Member
Posts: 31,680
Joined: Nov 10 2007
Gold: 1.00
Nov 30 2009 12:41am
Code
#include <windows.h>
#include <iostream>
using namespace std;

/////////////////////////////////////////////////////////////////////////////
//
//  CompareBitmaps
//    Compares two HBITMAPs to see if they contain the same image
//
//  Parameters :
//    HBitmapLeft  [in] : The HBITMAP handles that are to be compared
//    HBitmapRight [in] :
//
//  Returns :
//    true if the bitmaps are the same
//    false if they are different
//
/////////////////////////////////////////////////////////////////////////////


bool CompareBitmaps(HBITMAP HBitmapLeft, HBITMAP HBitmapRight)
{
   if (HBitmapLeft == HBitmapRight)
   {
       return true;
   }

   if (NULL == HBitmapLeft || NULL == HBitmapRight)
   {
       return false;
   }

   bool bSame = false;

   HDC hdc = GetDC(NULL);
   BITMAPINFO BitmapInfoLeft = {0};
   BITMAPINFO BitmapInfoRight = {0};

   BitmapInfoLeft.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
   BitmapInfoRight.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);

   if (0 != GetDIBits(hdc, HBitmapLeft, 0, 0, NULL, &BitmapInfoLeft, DIB_RGB_COLORS) &&
       0 != GetDIBits(hdc, HBitmapRight, 0, 0, NULL, &BitmapInfoRight, DIB_RGB_COLORS))
   {
       // Compare the BITMAPINFOHEADERs of the two bitmaps

       if (0 == memcmp(&BitmapInfoLeft.bmiHeader, &BitmapInfoRight.bmiHeader,
           sizeof(BITMAPINFOHEADER)))
       {
           // The BITMAPINFOHEADERs are the same so now compare the actual bitmap bits

           BYTE *pLeftBits = (BYTE*)BitmapInfoLeft.bmiHeader.biSizeImage;
           BYTE *pRightBits = (BYTE*)BitmapInfoRight.bmiHeader.biSizeImage;
           BYTE *pByteLeft = NULL;
           BYTE *pByteRight = NULL;

           PBITMAPINFO pBitmapInfoLeft = &BitmapInfoLeft;
           PBITMAPINFO pBitmapInfoRight = &BitmapInfoRight;

           // calculate the size in BYTEs of the additional

           // memory needed for the bmiColor table

           int AdditionalMemory = 0;
           switch (BitmapInfoLeft.bmiHeader.biBitCount)
           {
           case 1:
               AdditionalMemory = 1 * sizeof(RGBQUAD);
               break;
           case 4:
               AdditionalMemory = 15 * sizeof(RGBQUAD);
               break;
           case 8:
               AdditionalMemory = 255 * sizeof(RGBQUAD);
               break;
           case 16:
           case 32:
               AdditionalMemory = 2 * sizeof(RGBQUAD);
           }

           if (AdditionalMemory)
           {
               // we have to allocate room for the bmiColor table that will be

               // attached to our BITMAPINFO variables

               pByteLeft = new BYTE[sizeof(BITMAPINFO) + AdditionalMemory];
               if (pByteLeft)
               {
                   memset(pByteLeft, 0, sizeof(BITMAPINFO) + AdditionalMemory);
                   memcpy(pByteLeft, pBitmapInfoLeft, sizeof(BITMAPINFO));
                   pBitmapInfoLeft = (PBITMAPINFO)pByteLeft;
               }

               pByteRight = new BYTE[sizeof(BITMAPINFO) + AdditionalMemory];
               if (pByteRight)
               {
                   memset(pByteRight, 0, sizeof(BITMAPINFO) + AdditionalMemory);
                   memcpy(pByteRight, pBitmapInfoRight, sizeof(BITMAPINFO));
                   pBitmapInfoRight = (PBITMAPINFO)pByteRight;
               }
           }

           if (pLeftBits && pRightBits && pBitmapInfoLeft && pBitmapInfoRight)
           {
               // zero out the bitmap bit buffers

               memset(pLeftBits, 0, BitmapInfoLeft.bmiHeader.biSizeImage);
               memset(pRightBits, 0, BitmapInfoRight.bmiHeader.biSizeImage);

               // fill the bit buffers with the actual bitmap bits

               if (0 != GetDIBits(hdc, HBitmapLeft, 0,
                   pBitmapInfoLeft->bmiHeader.biHeight, pLeftBits, pBitmapInfoLeft,
                   DIB_RGB_COLORS) && 0 != GetDIBits(hdc, HBitmapRight, 0,
                   pBitmapInfoRight->bmiHeader.biHeight, pRightBits, pBitmapInfoRight,
                   DIB_RGB_COLORS))
               {
                   // compare the actual bitmap bits of the two bitmaps

                   bSame = 0 == memcmp(pLeftBits, pRightBits,
                       pBitmapInfoLeft->bmiHeader.biSizeImage);
               }
           }

           // clean up

           delete[] pLeftBits;
           delete[] pRightBits;
           delete[] pByteLeft;
           delete[] pByteRight;
       }
   }

   ReleaseDC(NULL, hdc);

   return bSame;
}

bool SaveBMPFile(char *filename, HBITMAP bitmap, HDC bitmapDC, int width, int height);

bool ScreenCapture(int x, int y, int width, int height, char *filename) {

   // get a DC compat. w/ the screen
   HDC hDc = CreateCompatibleDC(0);

   // make a bmp in memory to store the capture in
   HBITMAP hBmp = CreateCompatibleBitmap(GetDC(0), width, height);

   // join em up
   SelectObject(hDc, hBmp);

   // copy from the screen to my bitmap
   BitBlt(hDc, 0, 0, width, height, GetDC(0), x, y, SRCCOPY);

   // save my bitmap
   //bool ret = SaveBMPFile(filename, hBmp, hDc, width, height);

   // free the bitmap memory
   DeleteObject(hBmp);

   return false;
}

void TestSS(int x, int y, int iWidth, int iHeight, int CopyX, int CopyY, HWND hwnd) {

   HDC hDC, hDCMem, Source;
   HBITMAP hBitmap;
//    int iWidth, iHeight;

   // Retrieve the handle to a display device context for the client
   // area of the window.
   hDC = GetDC(0);
   Source = GetDC(hwnd);

   // Create a memory device context compatible with the device.
   hDCMem = CreateCompatibleDC(hDC);

   // Retrieve the width and height of window display elements.
   //iWidth = GetSystemMetrics(SM_CXSCREEN) / 10;
   //iHeight = GetSystemMetrics(SM_CYSCREEN) / 10;

   // Create a bitmap compatible with the device associated with the
   // device context.
   hBitmap = CreateCompatibleBitmap(hDC, iWidth, iHeight);
MessageBox(NULL, "BitBlt activating...", "WARNING", MB_ICONERROR);
   //BitBlt(GetDC(0), 300, 300, 300, 300, GetDC(0), 0, 0, SRCCOPY);
   BitBlt(Source, x, y, iWidth, iHeight, hDC, CopyX, CopyY, SRCCOPY);

   // Delete the bitmap object and free all resources associated with it.
   DeleteObject(hBitmap);

   // Delete the memory device context and the display device context.
   DeleteDC(hDCMem);
   DeleteDC(hDC);

   return;
}

void TestSS2(HWND hwnd, DWORD dwWindowX, DWORD dwWindowY) {

   HDC hScreenDC = GetDC(hwnd); //global screen DC
   HDC hCompatibleDC = CreateCompatibleDC(hScreenDC);

   HBITMAP screenshot = CreateCompatibleBitmap(hScreenDC, dwWindowX, dwWindowY);
   SelectObject(hCompatibleDC, screenshot);

   BitBlt(hCompatibleDC, 50, 50, dwWindowX, dwWindowY, hScreenDC, 50, 50, SRCCOPY);

   ReleaseDC(NULL, hScreenDC);
   DeleteDC(hCompatibleDC);

   return;
}

void Test3() {

   HDC hdcScreen, hdcMemory;
   int cxScreen, cyScreen;
   HBITMAP hbmMemory, hbmOld;
   BITMAPINFO bi;
   void* data;

   // get the HDC of the screen
   hdcScreen = GetDC(NULL);

   // get the screen size
   cxScreen = GetSystemMetrics(SM_CXSCREEN) / 10;
   cyScreen = GetSystemMetrics(SM_CYSCREEN) / 10;

   // create a compatible memory dc/bitmap pair
   hdcMemory = CreateCompatibleDC(hdcScreen);
   hbmMemory = CreateCompatibleBitmap(hdcScreen, cxScreen, cyScreen);
   hbmOld = (HBITMAP)SelectObject(hdcMemory, hbmMemory);

   // "capture" the screen into this pair
   BitBlt(hdcMemory, 0, 0, cxScreen, cyScreen, hdcScreen, 0, 0, SRCCOPY);

   // now that we got the screen into the HBITMAP, get its bits

   // we want to get it as 24-bpp
   ZeroMemory(&bi, sizeof(BITMAPINFO));
   bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
   bi.bmiHeader.biWidth = cxScreen;
   bi.bmiHeader.biHeight = cyScreen;
   bi.bmiHeader.biBitCount = 24;
   bi.bmiHeader.biPlanes = 1;

   // first call with a NULL pointer to fill in rest of bi.bmiHeader
   GetDIBits(hdcMemory, hbmMemory, 0, cyScreen, NULL, &bi, DIB_RGB_COLORS);

   // allocate memory (size is in bi.bmiHeader.biSizeImage)
   data = malloc(bi.bmiHeader.biSizeImage);

   // now get the data
   GetDIBits(hdcMemory, hbmMemory, 0, cyScreen, data, &bi, DIB_RGB_COLORS);

if (CompareBitmaps(hbmMemory, hbmOld)) { MessageBox(0, "TRUE", "TRUE", MB_OK); } else { MessageBox(0, "FALSE", "FALSE", MB_OK); }

   // clean-up
   SelectObject(hdcMemory, hbmOld);
   DeleteDC(hdcMemory);
   DeleteObject(hbmMemory);

   // thats it.
   // data = the data
   //    1. 24 bpp BGR format
   //    2. 32-bit padded scanlines
   //    3. upside down
   // cxScreen = width
   // cyScreen = height
   return;
}

/*
int main() {

   AllocConsole();
   HANDLE outHandle = GetStdHandle(STD_OUTPUT_HANDLE);

   //TestSS2(hwnd, 500, 500);
   while (true) {
       Sleep(50);

      // if (GetAsyncKeyState(VK_HOME)) { Test3(); }
       if (GetAsyncKeyState(VK_HOME)) {
           HDC hDc = CreateCompatibleDC(0);
           HBITMAP hBmp = CreateCompatibleBitmap(hDc, 50, 50);

           BITMAP bmpOrig;
           GetObject(hBmp, sizeof(BITMAP), &bmpOrig);
           int sizeOrig = bmpOrig.bmWidthBytes * bmpOrig.bmHeight;
           BYTE* pDataOrig = new BYTE[sizeOrig];
           GetBitmapBits(hBmp, sizeOrig, pDataOrig);
           SelectObject(hDc, hBmp);

           char ImagePixel[500] = {'\0'};
           sprintf(ImagePixel, "Image size: %d\n", sizeOrig);
           WriteConsole(outHandle, ImagePixel, strlen(ImagePixel), NULL, NULL);

           for (int x = 0; x < sizeOrig; x++) {
               sprintf(ImagePixel, "pDataOrig[%d]: %d\n", x, pDataOrig[x]);
               WriteConsole(outHandle, ImagePixel, strlen(ImagePixel), NULL, NULL);
           }

           SIZE Temp;
           GetBitmapDimensionEx(hBmp, &Temp);

//            long ImageSize = Temp.cx * Temp.cy;
//            long *MyImage;
//            GetBitmapBits(hBmp, ImageSize, MyImage);

           //char ImagePixel[5000] = {'\0'};
//            sprintf(ImagePixel, "Image size: %d\n", ImageSize);
//            WriteConsole(outHandle, ImagePixel, strlen(ImagePixel), NULL, NULL);

//            for (int x = 0; x < ImageSize; x++) {
//                sprintf(ImagePixel, "%d\n", MyImage[x]);
//                WriteConsole(outHandle, ImagePixel, strlen(ImagePixel), NULL, NULL);
//            }

           BitBlt(GetDC(0), 300, 300, 300, 300, GetDC(0), 0, 0, SRCCOPY);
           DeleteObject(hBmp);
       }

       if (GetAsyncKeyState(VK_END)) { exit(0); }
   }

   //TestSS(250, 250, 500, 500, 50, 50, hwnd);

//    HDC hDc = CreateCompatibleDC(0);
//    HBITMAP hBmp = CreateCompatibleBitmap(GetDC(0), 50, 50);
//    SelectObject(hDc, hBmp);

//    BitBlt(GetDC(0), 300, 300, 300, 300, GetDC(0), 0, 0, SRCCOPY);
//    DeleteObject(hBmp);

   return 0;
}
*/

int main() {

   AllocConsole();
   HANDLE outHandle = GetStdHandle(STD_OUTPUT_HANDLE);

  HANDLE hBitMap = LoadImage(0, "C:\\Documents and Settings\\Compaq_Owner\\My Documents\\My Shit\\Programming projects\\Current\\Runescape bots\\Runescape Library\\Screen shot\\img.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
char ImagePixel[500] = {'\0'};
   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, "C:\\Documents and Settings\\Compaq_Owner\\My Documents\\My Shit\\Programming projects\\Current\\Runescape bots\\Runescape Library\\Screen shot\\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 );
       cout << bitmap2.bmBitsPixel;
                       sprintf(ImagePixel, "bitmap2.bmBitsPixel %d", bitmap2.bmBitsPixel);
                       WriteConsole(outHandle, ImagePixel, strlen(ImagePixel), NULL, NULL);
   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++ ) {
                       sprintf(ImagePixel, "%d", tmpY);
                       WriteConsole(outHandle, ImagePixel, strlen(ImagePixel), NULL, NULL);
                 }
             }
        }
   }

   system("PAUSE");
   return 0;
}


A collection of various functions I found googling a while back, I haven't gone back to trying to get this to work, but I'd like to start on it again.

My question is: How do you compare one image against another?
Member
Posts: 11,637
Joined: Feb 2 2004
Gold: 434.84
Nov 30 2009 07:40am
Quote (Muted @ Nov 30 2009 02:41am)

My question is: How do you compare one image against another?


Define compare. Do you just want to know if images are the same bitwise? Do you want to ignore header info and compare the part that you see?

Member
Posts: 31,680
Joined: Nov 10 2007
Gold: 1.00
Dec 1 2009 02:10pm
Quote (rockonkenshin @ 30 Nov 2009 08:40)
Define compare. Do you just want to know if images are the same bitwise? Do you want to ignore header info and compare the part that you see?


Here's what I want: A quicker, easier, more effective method than using a for loop and GetPixel().
What I want is the exact methodology of GetPixel() except load the entire image into memory (so it's quicker), and compare it against a "screen shot" (another image in memory).

Compare as in how GetPixel() functions -> Comparing the RGB values.
Member
Posts: 6,953
Joined: Sep 27 2003
Gold: 518.50
Dec 1 2009 03:15pm
Quote (Muted @ Dec 1 2009 03:10pm)
Here's what I want: A quicker, easier, more effective method than using a for loop and GetPixel().
What I want is the exact methodology of GetPixel() except load the entire image into memory (so it's quicker), and compare it against a "screen shot" (another image in memory).

Compare as in how GetPixel() functions -> Comparing the RGB values.

And since the GDI+ method Bitmap::GetPixel (http://msdn.microsoft.com/en-us/library/ms536297(VS.85).aspx) fits your requirements of having the bitmap in memory and can have the Color be compared to whatever you want, why not just use that in a for loop? I realize you say you want a blah blah blah and not use it in a for loop, but what is wrong with doing it this way? Microsoft isn't retarded -- the method is quite fast.

The *faster* way (and not significantly so, since it costs more memory) is to copy the content of the bitmap handle to an array and walk over it in pointers. You can do it like you are with GetBitmapBits, or you can use a BitmapData object (http://msdn.microsoft.com/en-us/library/ms534421(VS.85).aspx). Either one works.
Member
Posts: 31,680
Joined: Nov 10 2007
Gold: 1.00
Dec 3 2009 12:08am
Quote (ASBands @ 1 Dec 2009 16:15)
And since the GDI+ method Bitmap::GetPixel (http://msdn.microsoft.com/en-us/library/ms536297(VS.85).aspx) fits your requirements of having the bitmap in memory and can have the Color be compared to whatever you want, why not just use that in a for loop?  I realize you say you want a blah blah blah and not use it in a for loop, but what is wrong with doing it this way?  Microsoft isn't retarded -- the method is quite fast.

The *faster* way (and not significantly so, since it costs more memory) is to copy the content of the bitmap handle to an array and walk over it in pointers.  You can do it like you are with GetBitmapBits, or you can use a BitmapData object (http://msdn.microsoft.com/en-us/library/ms534421(VS.85).aspx).  Either one works.


Here's why not:
ReadProcessMemory is capable of getting X number of bytes.
What you're saying is: Why not just loop through 200 bytes, one at a time, calling the same function over and over?
That's ludacris, and I'll just assume you don't know, because if you did, you'd have said it by now, which also explains why you dance around the bush on it.
Go Back To Programming & Development Topic List
Prev14567Next
Add Reply New Topic New Poll