Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all articles
Browse latest Browse all 3046

GetDIBits question.

$
0
0
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?

Viewing all articles
Browse latest Browse all 3046

Trending Articles