GetDIBits question.
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Thread: GetDIBits question.

Threaded View

  1. #1
    Join Date
    Apr 2013
    Posts
    34

    GetDIBits question.

    sorry, I hate posting 2 questions about the same (or, at least, similar) topic, i thought i had my getpixel issue solved... but... I didn't

    so I'm trying to use GetDIBits, since I am capable of taking an image of the Minecraft window and copying it to a clipboard sucessfully.

    problem is, I don't have much of an Idea how to use GetDIBits, I have some working code written:

    Code:
    #include <Windows.h>
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        HBITMAP hBitmap = (HBITMAP) LoadImage(0, L"C:/Foo.bmp" ,IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
        // check hBitmap for error
    
    
        BITMAP bm;
        ::GetObject( hBitmap , sizeof(bm) , &bm );
    
    	 /* Omitting error checks for brevity */
        HDC dcBitmap = CreateCompatibleDC ( NULL );
        SelectObject( dcBitmap, hBitmap );
    
        BITMAPINFO bmpInfo;
        bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
        bmpInfo.bmiHeader.biWidth = bm.bmWidth;
        bmpInfo.bmiHeader.biHeight = -bm.bmHeight;
        bmpInfo.bmiHeader.biPlanes = 1;
        bmpInfo.bmiHeader.biBitCount = 24;
        bmpInfo.bmiHeader.biCompression = BI_RGB;        
        bmpInfo.bmiHeader.biSizeImage = 0;        
    
        COLORREF* pixel = new COLORREF [ bm.bmWidth * bm.bmHeight ];
        GetDIBits( dcBitmap , hBitmap , 0 , bm.bmHeight , pixel , &bmpInfo , DIB_RGB_COLORS );
    	
        int r = GetRValue ( *pixel );
        int g = GetGValue ( *pixel );
        int b = GetBValue ( *pixel );
        cout << r << " " << g << " " << b << endl;
    
        bm.bmHeight = bm.bmHeight - 1;
        GetDIBits( dcBitmap , hBitmap , 0 , bm.bmHeight , pixel , &bmpInfo , DIB_RGB_COLORS );
        r = GetRValue ( *pixel );
        g = GetGValue ( *pixel );
        b = GetBValue ( *pixel );
        cout << r << " " << g << " " << b << endl;
        cin.get();
    
        return 0;
    }

    I just used a small image I made in ms pain as a test for now.

    problem is, I can retrieve the first pixel of every scan line by editing "bm.bmHeight" but I can't figure out how to
    grab the second (or third, or fourth) pixel in each scan line.

    any help?
    Last edited by peteandperry; June 13th, 2013 at 03:54 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center