Skip to main content
GameDev.net gamedev.net
🔒 Locked

Take Screenshots Easy

Started by b1gjo3 Jul 2, 2009 at 2:40 PM 6 replies 1.3k views
Original Post
b1gjo3
b1gjo3
Hi everyone, i just finished a very small project in c++ to take screenshots of the entire screen with one simple function. It uses GDI+ lib heres a link to download, http://www.megaupload.com/?d=2ZOYGT4B heres some sample code

#include <screenshot.hpp>
#pragma comment(lib, "screenshot")

int main(int argc, char** argv)
{
    ScrLib::TakeScreenshot("C:\\screenshot.bmp"); //save as bmp
    ScrLib::TakeScreenshot("C:\\screenshot.jpg"); //save as jpg
    return 0;
}


all you do is specify the path you want to save to, and it will automatically save it as bmp, jpg, jpeg, gif, tiff, png depending on what you specified. hope this will help someone in the future. thanks, leave constructive criticism only
fastcall22
fastcall22
You can do the same with ctrl+PrintScreen and pasting into a paint program.
Halifax2
Halifax2
Quote:
Original post by _fastcall
You can do the same with ctrl+PrintScreen and pasting into a paint program.

True, but what if you want to take a development debugging screenshot to see how the frame looks while only 50% of the frame has been rendered. You can't really get that type of time resolution and precision with your eyes and using that keystroke.

Overall, ctrl+PrintScreen is probably the best option, but this definitely is not without its uses.

[Edited by - Halifax2 on July 2, 2009 5:45:32 PM]
Denzel Morris (@drdizzy) :: Software Engineer :: SkyTech Enterprises, Inc.
"When men are most sure and arrogant they are commonly most mistaken, giving views to passion without that proper deliberation which alone can secure them from the grossest absurdities." - David Hume
b1gjo3
b1gjo3
Quote:
Original post by _fastcall
You can do the same with ctrl+PrintScreen and pasting into a paint program.


hehe, this is true indeed. but i would hardly be called a programmer if i had to do something manually lol.
riruilo
riruilo
Very useful and super easy-to-use.
A multiplatform version (linux/mac) would be nice.
I've seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I watched C-beams glitter in the dark near the Tannhauser gate. All those moments will be lost in time, like tears in rain. Time to die.
adeyblue
adeyblue
Few things:

Any reason you check whether GetDC fails, but not CreateCompatibleDC/CreateCompatibleBitmap? Also if GetDC() does fail, trying to continue taking the screenshot as the code does is futile. It can't possibly succeed.

You shouldn't use free() on memory returned by new[] (the wide string buffer for MultiByteToWideChar), use delete[].

And a tip, if you've got a std::string you can use string.length() to get its length. strlen() on the original char* is not neccessary.
george135
george135
The right code is in MSDN for years (GDI and GDI+), but both samples are not the best method (slow) for Screen Capture.
The best method is with DX, in DX SDK
b1gjo3
b1gjo3
Quote:
Original post by george135
The right code is in MSDN for years (GDI and GDI+), but both samples are not the best method (slow) for Screen Capture.
The best method is with DX, in DX SDK


would'nt the end user have to have dx installed though, when i made it i wanted it to have very little dependencies, and high portability (still working on this part)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.