How to take Screen shot using C++

Nov 26, 2011 at 2:30pm
Hi,
I want to take screen shot and save it in any image format like jpg, bmp, ppm or any other . Please help me as soon as possible.
Nov 26, 2011 at 2:36pm
C++ knows nothing of your screen. How to do this is dependent on your operating system. If you're using Windows, try this: http://planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=10754&lngWId=3
Last edited on Nov 26, 2011 at 2:37pm
Nov 26, 2011 at 2:36pm
There is no standard way, that's for sure. You probably have to look into whatever functions the system you are using provides.
Nov 26, 2011 at 2:47pm
The program I use to capture screens, is a free program called, 'Zoom It'. You can download it at
http://technet.microsoft.com/en-us/sysinternals/bb897434
Nov 26, 2011 at 2:49pm
Do you actually need to write your own code for this, or can you just press "Print Screen"?
Nov 26, 2011 at 4:32pm
there will be a button on your laptop keypad (prt sc)... if it is in a box press the function key(fn) and then press that key(prt sc).... then got to paint and paste it using ctrl+v..
Nov 26, 2011 at 4:39pm
dear Moschops there is problem in your code at GetDIBits(hdc,h,0,bmpInfo.bmiHeader.biHeight,pBuf, &bmpInfo, DIB_RGB_COLORS);
error is undefined GetDiBits@28. please help me to solve it.
Nov 26, 2011 at 6:14pm
i think, you have to involve in windows.h....
Last edited on Nov 27, 2011 at 9:22am
Nov 26, 2011 at 6:28pm
You don't mention if you're targetting Windows or some other o/s

In the Windows case, it's harder work to save the data than capture it (that's just a case of getting hold of the desktop window, creating a compatible bitmap, and a BitBlt). Gdi+ provides much better facilities for format conversion, so I'd recommend it over regular GDI in this case (out of interest I once coded the same thing long hand in GDI and it's rather longer than the GDI equiv)

Last edited on Nov 26, 2011 at 6:31pm
Nov 26, 2011 at 6:31pm
please help me to solve it.


You're not linking against the correct libraries.
Nov 26, 2011 at 9:28pm
closed account (236Rko23)
@ Naqvi
you high or what? -.-

@ mudassar24
you could try looking at virtual dub source code, it has a screen capture section, so you could try to see how does it do it

your best bet would be finding some open source screen capturing software and reading it's code. both linux and windows
Nov 26, 2011 at 10:20pm
For a basic, plain WIN32 example:

Capturing an Image
http://msdn.microsoft.com/en-us/library/dd183402(v=vs.85).aspx

The following example code is from an application that captures an image of the entire desktop, scales it down to the current window size and then saves it to a file.

This sample saves the image as a bitmap (.bmp) file. But:

"How can I take a screenshot and save it as JPEG on Windows?"
http://stackoverflow.com/questions/997175/how-can-i-take-a-screenshot-and-save-it-as-jpeg-on-windows

uses a similar approach, but using GdiPlus to save as .jpeg.

Andy

P.S. There are a number of basic examples of different capture methods for Windows in CodeGuru.com and CodeProject.com.
Last edited on Nov 26, 2011 at 10:30pm
Topic archived. No new replies allowed.