Take the 2-minute tour ×

I'm creating an application to capture a small area of the screen and compare it to a library of images saved to disk. I wrote a similar application a few years ago in .net and used bitblt and the WINAPI. Performance is really important and I don't mind delving into openGL if it would make a difference with performance.

share|improve this question
What do you mean by “select an area of the screen”? Just specifying a rectangle programmatically, or do you intend to let the user specify it—and if so, what user interface are you imagining for it? –  Peter Hosey Jan 4 '12 at 12:21
Yes just specifying a rectangle programmatically. There won't be a user interface. thanks. –  Monty Jan 4 '12 at 12:49

1 Answer 1

You could use some code like this:

    NSImage *resultingImage = nil;
    CGImageRef image;
    CGWindowID  windowID = (CGWindowID)[[self window] windowNum];
    image = CGWindowListCreateImage(NSRectToCGRect(captureRect), kCGWindowListOptionIncludingWindow|kCGWindowListOptionOnScreenBelowWindow, windowID, kCGWindowImageDefault);
    resultingImage = [[NSImage alloc] initWithCGImage:image size:NSZeroSize];
    return [resultingImage autorelease];
share|improve this answer
Thanks Tim! Is there any reason you designed it to return an NSImage rather than a CGImage or CIImage? –  Monty Jan 4 '12 at 19:35
You're welcome. Normally I prefer NSImage because many other Cocoa classes work better with it and because NSImage has some quite convenient methods. However, in the end the answer will depend on what exactly you want to do with the image and which other classes you will use. –  Tim Jan 4 '12 at 20:12
Thanks Tim, appreciate your time. –  Monty Jan 4 '12 at 20:32

Your Answer


