Last active
November 22, 2018 15:51
-
-
Save cbess/a3bc4df1d101ca567a0ca8c9ace25553 to your computer and use it in GitHub Desktop.
NSWindow screenshot, best method found (objc)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ref: https://stackoverflow.com/a/22967912/344591 | |
@implementation NSView (Screenshot) | |
/// Returns an image that contains the entire window contents, including window background color and traffic lights. | |
/// Resembles the product of taking a screenshot using Preview.app | |
- (NSImage *)screenshotOfWindow { | |
CGWindowID winID = (CGWindowID) self.window.windowNumber; | |
CGImageRef ref = CGWindowListCreateImage(CGRectNull, kCGWindowListOptionIncludingWindow, winID, kCGWindowImageBoundsIgnoreFraming); | |
return [[NSImage alloc] initWithCGImage:ref size:self.bounds.size]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment