views:

395

answers:

2

Is there a way to programatically take a screenshot (or somehow get access to an image) of the current screen display on a mac?

Preferably, in C++, not Objective-C.

+4  A: 

Here is a sample code that does it is C, however it is deprecated.

Also chech out glGrab which uses OpenGL to grab the screen and is very fast.

And there is this CocoaDev thread which has numerous implementations, both is Objective-C and C++.

FigBug
A: 

Use screencapture(1).

http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/screencapture.1.html

Invoke it with system() or posix_spawn().

cdespinosa