Skip to content

Instantly share code, notes, and snippets.

@nacho4d
Created October 13, 2011 06:48
Show Gist options
  • Save nacho4d/1283598 to your computer and use it in GitHub Desktop.
Save nacho4d/1283598 to your computer and use it in GitHub Desktop.
[Cocoa] NSView to PNG
/* NSView to PNG */
NSView *view = versionsButton; /* this is the view :) */
NSBitmapImageRep *rep = [view bitmapImageRepForCachingDisplayInRect:[view bounds]];
[view cacheDisplayInRect:[view bounds] toBitmapImageRep:rep];
NSData *data = [rep representationUsingType:NSPNGFileType properties:nil];
[data writeToFile:@"/path/to/the/a/nice/place/view.png" atomically:YES];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment