views:

533

answers:

1

How do you capture an NSImage of the screen in Cocoa? I need to know the fastest way, because I'm trying to make a screencasting app.

+2  A: 

See the OpenGLCaptureToMovie sample. I'd add that you should use Quartz Display Services' refresh-notification APIs instead of a timer.

Note that the OpenGL example doesn't produce NSImage objects. There's no point in doing so, since you can't put those into a movie. Well, I guess you could assign an NSImage at a specified frame time, but I don't know how well that would work with compression.

Speaking of compression, use the Animation codec at maximum quality for your recording. This provides decent enough compression to not overwhelm the disk, and certainly won't overwhelm the processors. You can then offer conversion options, such as H.264, H.264 for iPhone, and H.264 for iPod. You should also allow the user to keep the original file; some sites, such as Vimeo, will accept it and allow visitors to download it.

Peter Hosey