Created
March 28, 2011 05:39
-
-
Save fernyb/890044 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