C++ – How to take screenshot in Mac OS X using Cocoa or C++

ccocoamacos

How to take screenshot programmically of desktop area in Mac OS X ?

Best Answer

Two interesting options I have seen, but yet to use professionally, are the screencapture utility and a MacFuse demo.

The screencapture utility has been around since 10.2, according to the man page, and could be linked to a Cocoa application by use of NSTask.

The MacFuse demo worked by creating a new screenshot each time a folder was opened, or something like that. The idea being you could write a quick script to access the image when you needed it, without having to have the script actually run on that machine.

But seriously, Apple has some other sample code called "Son of Grab" which uses the new CGWindow API which is pretty awesome.

http://developer.apple.com/samplecode/SonOfGrab/