Bitmap scanning

This is a discussion on Bitmap scanning within the Windows Programming forums, part of the Platform Specific Boards category; I have heard about a function named "Get24BitPixels", which returns a pointer to the first bit in a bitmap or ...

  1. #1
    Politics&Cpp geek Da-Nuka's Avatar
    Join Date
    Oct 2004
    Posts
    104

    Bitmap scanning

    I have heard about a function named "Get24BitPixels", which returns a pointer to the first bit in a bitmap or something like that.
    But my compiler(Visual C++ 6.0) could not identify the function.

    Can someone tell me what functions and such, to use, if i want to
    scan through a bitmap, to see and compare each pixels color.
    (Those of you which is really into this might have figured out that i want to make a region fitting to a bitmap.)

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,673
    Perhaps reading more of the tutorial where google found it would help
    http://www.flipcode.com/articles/art...n32skins.shtml

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Ok yeah that didn't sound like an API function.. I found this code:

    Code:
    BYTE* Get24BitPixels(HBITMAP pBitmap, WORD *pwWidth, WORD *pwHeight)
    {
      // a bitmap object just to get bitmap width and height
    	BITMAP bmpBmp;
    
      // pointer to original bitmap info
    	LPBITMAPINFO pbmiInfo;
    
      // bitmap info will hold the new 24bit bitmap info
      BITMAPINFO bmiInfo;
    
      // width and height of the bitmap
      WORD wBmpWidth, wBmpHeight;
    
      // ---------------------------------------------------------
      // get some info from the bitmap
      // ---------------------------------------------------------
    	GetObject(pBitmap, sizeof(bmpBmp),&bmpBmp);
      pbmiInfo   = (LPBITMAPINFO)&bmpBmp;
    
      // get width and height
    	wBmpWidth  = (WORD)pbmiInfo->bmiHeader.biWidth;
    	wBmpWidth -= (wBmpWidth%4);                       // width is 4 byte boundary aligned.
    	wBmpHeight = (WORD)pbmiInfo->bmiHeader.biHeight;
    
      // copy to caller width and height parms
      *pwWidth  = wBmpWidth;
      *pwHeight = wBmpHeight;
      // ---------------------------------------------------------
    
    	// allocate width * height * 24bits pixels
      BYTE *pPixels = new BYTE[wBmpWidth*wBmpHeight*3];
    	if (!pPixels) return NULL;
    
      // get user desktop device context to get pixels from
    	HDC hDC = GetWindowDC(NULL);
    
      // fill desired structure
    	bmiInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    	bmiInfo.bmiHeader.biWidth = wBmpWidth;
    	bmiInfo.bmiHeader.biHeight = -wBmpHeight;
    	bmiInfo.bmiHeader.biPlanes = 1;
    	bmiInfo.bmiHeader.biBitCount = 24;
    	bmiInfo.bmiHeader.biCompression = BI_RGB;
    	bmiInfo.bmiHeader.biSizeImage = wBmpWidth*wBmpHeight*3;
    	bmiInfo.bmiHeader.biXPelsPerMeter = 0;
    	bmiInfo.bmiHeader.biYPelsPerMeter = 0;
    	bmiInfo.bmiHeader.biClrUsed = 0;
    	bmiInfo.bmiHeader.biClrImportant = 0;
    
      // get pixels from the original bitmap converted to 24bits
      int iRes = GetDIBits(hDC,pBitmap,0,wBmpHeight,(LPVOID)pPixels,&bmiInfo,DIB_RGB_COLORS);
    
      // release the device context
    	ReleaseDC(NULL,hDC);
    
      // if failed, cancel the operation.
    	if (!iRes)
      {
        delete pPixels;
        return NULL;
      };
    
      // return the pixel array
    	return pPixels;
    }
    From this article.

    [edit]
    Oops Salem beat me in with the same tactics.
    [/edit]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Loading a bitmap (Without using glaux)
    By Shamino in forum Game Programming
    Replies: 7
    Last Post: 03-16-2006, 08:43 AM
  2. OpenGL -- Bitmaps
    By HQSneaker in forum Game Programming
    Replies: 14
    Last Post: 09-06-2004, 04:04 PM
  3. Loading a Bitmap resource for OpenGL Texture[x]
    By the dead tree in forum Game Programming
    Replies: 4
    Last Post: 08-26-2004, 01:12 PM
  4. bitmap not going onto screen
    By stallion in forum Windows Programming
    Replies: 4
    Last Post: 02-22-2003, 09:07 AM
  5. texture is all white in opengl!
    By Crossbow in forum Game Programming
    Replies: 7
    Last Post: 03-31-2002, 10:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21