Skip to content

Instantly share code, notes, and snippets.

@kaishin
Created January 10, 2016 14:29
Show Gist options
  • Save kaishin/d4df8fc6c701ca635e25 to your computer and use it in GitHub Desktop.
Save kaishin/d4df8fc6c701ca635e25 to your computer and use it in GitHub Desktop.
NSView Snapshot
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
}
}
@hllovesgithub
Copy link

How to cache NSView filtered content?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment