Last active
November 22, 2018 15:51
Star
You must be signed in to star a gist
NSWindow screenshot, best method found (objc)
This file contains 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