Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

From screen dc to an array

alakesealakese Member Posts: 5
Hello,

i am writing an application, which captures every 100ms desktop, and then shows in a small window. (like windows zoom) With + and - you can zoom in or out it. I want to get the pixel data from screendc (after some zooms) and save it to an array.(i will change pixels and draw it again). I tried to get it with twice calling of GetDIBits, but didn t get succeed.
Has anyone read pixels in an array from a screendc?



Regards
Yasin

Comments

  • hdayvaryhdayvary Member Posts: 35
    : Hello,
    :
    : i am writing an application, which captures every 100ms desktop, and then shows in a small window. (like windows zoom) With + and - you can zoom in or out it. I want to get the pixel data from screendc (after some zooms) and save it to an array.(i will change pixels and draw it again). I tried to get it with twice calling of GetDIBits, but didn t get succeed.
    : Has anyone read pixels in an array from a screendc?
    :
    :
    :
    : Regards
    : Yasin
    :
    Hi
    See this :
    BITMAPINFO bitmapInfo;
    memset(&bitmapInfo, 0, sizeof(BITMAPINFO));
    bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    ::GetDIBits(hDC, hBitmap, 0, 1, 0, &bitmapInfo, DIB_RGB_COLORS);
    int iBitmapSize = iWidth * iHeight * 4;
    char* pBuff = new char[iBitmapSize];
    ::GetDIBits(hDC, hBitmap, 0, iHeight, pBuff, &bitmapInfo, DIB_RGB_COLORS);
    Good Luck
  • alakesealakese Member Posts: 5
    Hello,

    Thanks for answer,
    but my problem is, how can i get hdc and hbitmap from my window... i tried it like this:

    CRect rect;
    GetClientRect(&rect);
    int scrWidth = rect.right - rect.left;
    int scrHeight = rect.bottom - rect.top;

    HDC hDc = ::GetWindowDC(this->m_hWnd);
    HBITMAP hBitmap = CreateCompatibleBitmap(hDC, scrWidth, scrHeight);

    BITMAPINFO bitmapInfo;
    memset(&bitmapInfo, 0, sizeof(BITMAPINFO));
    bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    ::GetDIBits(hDc, hBitmap, 0, 1, 0, &bitmapInfo, DIB_RGB_COLORS);
    int iBitmapSize = scrWidth * scrHeight * 4;
    char* pBuff = new char[iBitmapSize];
    ::GetDIBits(hDc, hBitmap, 0, scrHeight, pBuff, &bitmapInfo, DIB_RGB_COLORS);

    and i wanted to see the result as an array
    FILE *f = fopen("f.txt", "w");
    for(int i = 0; i < iBitmapSize; i++)
    fprintf(f, "%d
    ", pBuff[i]);
    fclose(f);

    How can i get hdc and hbitmap correctly. I tried it in various ways, but didnt get succed yet.


    Regards
    Yasin

    : : Hello,
    : :
    : : i am writing an application, which captures every 100ms desktop, and then shows in a small window. (like windows zoom) With + and - you can zoom in or out it. I want to get the pixel data from screendc (after some zooms) and save it to an array.(i will change pixels and draw it again). I tried to get it with twice calling of GetDIBits, but didn t get succeed.
    : : Has anyone read pixels in an array from a screendc?
    : :
    : :
    : :
    : : Regards
    : : Yasin
    : :
    : Hi
    : See this :
    : BITMAPINFO bitmapInfo;
    : memset(&bitmapInfo, 0, sizeof(BITMAPINFO));
    : bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    : ::GetDIBits(hDC, hBitmap, 0, 1, 0, &bitmapInfo, DIB_RGB_COLORS);
    : int iBitmapSize = iWidth * iHeight * 4;
    : char* pBuff = new char[iBitmapSize];
    : ::GetDIBits(hDC, hBitmap, 0, iHeight, pBuff, &bitmapInfo, DIB_RGB_COLORS);
    : Good Luck
    :

  • alakesealakese Member Posts: 5
    Hello,

    I solved my problem, if it is neccessary for anyone i can send my solution.
    Thanks.


    Best regards
    Yasin

  • bhushan1980bhushan1980 Member Posts: 3
    : Hello,
    :
    : I solved my problem, if it is neccessary for anyone i can send my solution.
    : Thanks.
    :
    :
    : Best regards
    : Yasin
    :
    :

    Hi Yasin,
    In my application I am trying to draw multiple rectangles which take their Dimensions as the inputs from the users. Also on drawing them I want to implement drag functionality when user clicks left button on the mouse in a particular rectangle. I also want to get the mutual distances between the rectangles' centers. Every time user drags a particular rectangle, the inter rectangle distances change and hance they must be refreshed and updated. So kindly send me your solution, as it would be of great help for me. Also, send me some clues as they would be valuable inputs for my application.

    Regards,
    Bhushan


Sign In or Register to comment.