Skip to content

Instantly share code, notes, and snippets.

Created June 7, 2015 19:47
What would you like to do?
Swift: create PNG from NSView
func makePNGFromView(view: NSView) {
var rep = view.bitmapImageRepForCachingDisplayInRect(view.bounds)!
view.cacheDisplayInRect(view.bounds, toBitmapImageRep: rep)
if let data = rep.representationUsingType(NSBitmapImageFileType.NSPNGFileType, properties: [:]) {
data.writeToFile("/xxx/image.png", atomically: false)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment