Created
October 13, 2011 06:48
-
-
Save nacho4d/1283598 to your computer and use it in GitHub Desktop.
[Cocoa] NSView to PNG
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
/* 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