Skip to content

Instantly share code, notes, and snippets.

@chinmaygarde
Created January 27, 2013 09:12
Show Gist options
  • Save chinmaygarde/4647506 to your computer and use it in GitHub Desktop.
Save chinmaygarde/4647506 to your computer and use it in GitHub Desktop.
Mac OSX Screen Capture
CGImageRef imageRef = CGWindowListCreateImage(CGRectInfinite, kCGWindowListOptionAll, kCGNullWindowID, kCGWindowImageDefault);
CFMutableDataRef dataRef = CFDataCreateMutable(kCFAllocatorDefault, 0);
CGImageDestinationRef dest = CGImageDestinationCreateWithData(dataRef, kUTTypePNG, 1, NULL);
CGImageDestinationAddImage(dest, imageRef, NULL);
CGImageDestinationFinalize(dest);
CFRelease(dest);
CGImageRelease(imageRef);
// Do stuff with data
[(__bridge NSData *)dataRef writeToFile:@"/Users/Buzzy/Desktop/screen.png" atomically:YES];
CFRelease(dataRef);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment