Created
January 10, 2016 14:29
-
-
Save kaishin/d4df8fc6c701ca635e25 to your computer and use it in GitHub Desktop.
NSView Snapshot
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
extension NSView { | |
var snapshot: NSImage { | |
guard let bitmapRep = bitmapImageRepForCachingDisplayInRect(bounds) else { return NSImage() } | |
bitmapRep.size = bounds.size | |
cacheDisplayInRect(bounds, toBitmapImageRep: bitmapRep) | |
let image = NSImage(size: bounds.size) | |
image.addRepresentation(bitmapRep) | |
return image | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to cache NSView filtered content?