C Board  

Go Back   C Board > Platform Specific Boards > Windows Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 01-23-2010, 06:21 PM   #1
Registered User
 
Join Date: Jan 2010
Posts: 4
ScreenShot-10 times in one second and showing it in Image component

Hi, I have a big problem. I want to do a program which will get a part of the screen of a program. After that It will show this small rectangle in Image component in BCB. But the problem is, it has to refresh it at least 10 times in one second. For now I succeeded in doing a code that gets a screen but it is too slow. It is refreshing in 2,5-3 seconds(It is copying all pixels separately by GetPixel() function to Image):/ This code below is within a loop. It should show the window but it shows only black screen. When I'm using analogical code but with loading a bitmap from file everthing works fine.

1.

Code:
    HDC WinDC;
    HDC CopyDC;
    HBITMAP hBitmap;
    RECT rt;
    HWND Wnd=FindWindow(NULL,"WINDOW");
              if(Wnd==0) {MessageBox(0,"didnt found the window!",0,0);}
    GetWindowRect (Wnd, &rt);
    WinDC = GetDC (Wnd);
    CopyDC = CreateCompatibleDC (global_hdc);
    std::cout<<rt.right - rt.left<<std::endl;
    std::cout<<rt.bottom - rt.top<<std::endl;
    hBitmap = CreateCompatibleBitmap (WinDC,
                                                                800, //width
                                                                600);//height
    SelectObject (CopyDC, hBitmap);
    BitBlt (global_hdc, //destination
               0,0,
               800, //width
               600, //height
               CopyDC, //source
               0, 0,
               SRCCOPY);
    DeleteObject((HBITMAP)hBitmap);
    DeleteDC(CopyDC);
2.Analogical code with loading from file:

Code:
    HBITMAP image;
    BITMAP bm;
    HDC hdcMem;
    //load the bitmap image
    image = (HBITMAP)LoadImage(0,"asteroid.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
    //read the bitmap's properties
    GetObject(image, sizeof(BITMAP), &bm);
    //create a device context for the bitmap
    hdcMem = CreateCompatibleDC(global_hdc);
    SelectObject(hdcMem, image);
    //draw the bitmap to the window (bit block transfer)
    BitBlt(
               global_hdc, //destination device context
               0, 0, //x,y location on destination
               bm.bmWidth, bm.bmHeight, //width,height of source bitmap
               hdcMem, //source bitmap device context
               0, 0, //start x,y on source bitmap
               SRCCOPY); //blit method
    //delete the device context and bitmap
    DeleteDC(hdcMem);
    DeleteObject((HBITMAP)image);
EDIT:

I want to get a part of window in a game and want to show this rectangle on my form. I've chosen Image component(BCB) for that but I'm not sure that it is enough fast way. I've got known that the problem is that I don't load the bitmap(of the black screen). So I have to load about 10 or more pictures per second from DC of this game window, am I right? But I don't have any idea how to load it from window and put in the image component(I think Image component don't have HDC so I can't use BitBlt function?).

I would be also grateful for orienting me how to analize pixels as fastly as possible. I mean I want analize about 50000 pixels four times in one second(checking if their color is red).

Last edited by arva; 01-24-2010 at 08:40 AM.
arva is offline   Reply With Quote
Old 01-23-2010, 11:30 PM   #2
and the hat of Jobseeking
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,630
ScreenShot-10 times in one second and showing it in Image component - C++

You didn't read this sites code posting guidelines.

Or choose carefully...
How To Ask Questions The Smart Way
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.

Salem is offline   Reply With Quote
Old 01-24-2010, 10:03 PM   #3
Registered User
 
Join Date: Jan 2010
Posts: 183
Is this from a Direct3D game?
From my experience the performance of Direct3D-GDI interactions is very poor. (Personally I find GDI performance in it self to be quite lacking)
Assuming that you don't have the source code of said game; What I would do is something like
Hook Direct3D9::Present or EndScene in the game
Read out the back buffer and write the pixel data to a shared memory mapped file
Read said pixel data from my external app and render it to a Direct3D surface.

There are probably easier ways of getting pixel data from a D3D window, but this way you also get the added benefit of being able to control the target's rendering pipeline
_Mike is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump


All times are GMT -6. The time now is 09:53 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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