Psiaki

Using Win32 and the C language, is there an easy way to give a program the ability to capture the image of the entire screen and then convert the image bitmap into a stream of bytes


Re: Visual C++ General screen capture

Bite Qiu - MSFT

Psiaki wrote:
Using Win32 and the C language, is there an easy way to give a program the ability to capture the image of the entire screen and then convert the image bitmap into a stream of bytes

To capture screen to a bitmap, try following code:

Code Snippet

// Get screen size
int nWidth = GetSystemMetrics(SM_CXSCREEN);
int nHeight = GetSystemMetrics(SM_CYSCREEN);

// Get desktop DC, create a compatible dc, create a comaptible bitmap and select into compatible dc.
HDC hDDC = GetDC( GetDesktopWindow() );
HDC hCDC = CreateCompatibleDC(hDDC);
HBITMAP hBitmap =CreateCompatibleBitmap(hDDC,nWidth,nHeight);
SelectObject(hCDC,hBitmap);
BitBlt(hCDC,0,0,nWidth,nHeight,hDDC,0,0,SRCCOPY|CAPTUREBLT);

/* save hBitmap to stream of byte as you mentioned */

// Release the objects
ReleaseDC( GetDesktopWindow(),hDDC);
DeleteDC(hCDC);
DeleteObject(hBitmap);

I am not sure what do you mean by "convert the image bitmap into a stream of bytes", are you trying to store only pixel information to a byte array or entire bitmap to a byte array, for either of above, MSDN will give you more information: http://msdn2.microsoft.com/en-us/library/ms532340.aspx, If you get no luck from this link, please feel free to follow up.

hopt it helps

rico






Re: Visual C++ General screen capture

Simple Samples

For questions such as this, it can be useful to look in the Windows (Platform) SDK. There is a sample called Wincap32, or at least there was and it should still be there. It is a sample ported from 16-bit Windows so the relevant code should be easily used by a C program.

Also, you can use the Communities menu in VC 2005 to find web sites with articles and samples; this question is one that is commonly answered in articles and samples.






Re: Visual C++ General screen capture

prashant.jain

hi.. I am also doing the same thing and probably in the same way as given in your code. I am converting it from ddb to dib format . But I want to compress it before storing it in DAT format. How to proceed with this. Is there any way by which i can specify upto what limit to compress. thanx





Re: Visual C++ General screen capture

Ramkrishna Pawar

Compare with what There is not good way to compare if the picture is same, one can compare it on Data level though.






Re: Visual C++ General screen capture

danni123

Is it possible to save the Bitmap to JPG