-
-
Save maheshgiri/8eb0874f8900a31f8048bba82cd8744e to your computer and use it in GitHub Desktop.
NSWindow Categories to get screen capture of NSWindow including the shadow
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
@interface NSWindow (FRBExtra) | |
- (NSImage *)windowImage; | |
- (CGImageRef)windowImageShot; | |
@end |
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
@implementation NSWindow (FRBExtra) | |
- (NSImage *)windowImage | |
{ | |
NSImage * image = [[NSImage alloc] initWithCGImage:[self windowImageShot] size:[self frame].size]; | |
[image setDataRetained:YES]; | |
[image setCacheMode:NSImageCacheNever]; | |
return [image autorelease]; | |
} | |
- (CGImageRef)windowImageShot | |
{ | |
CGWindowID windowID = (CGWindowID)[self windowNumber]; | |
CGWindowImageOption imageOptions = kCGWindowImageDefault; | |
CGWindowListOption singleWindowListOptions = kCGWindowListOptionIncludingWindow; | |
CGRect imageBounds = CGRectNull; | |
CGImageRef windowImage = CGWindowListCreateImage(imageBounds, singleWindowListOptions, windowID, imageOptions); | |
return (CGImageRef)[NSMakeCollectable(windowImage) autorelease]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment