Skip to content

Instantly share code, notes, and snippets.

@Moligaloo
Created November 11, 2013 06:59
Show Gist options
  • Save Moligaloo/7409049 to your computer and use it in GitHub Desktop.
Save Moligaloo/7409049 to your computer and use it in GitHub Desktop.
Save NSImage to png file
+ (void)saveImage:(NSImage *)image atPath:(NSString *)path {
CGImageRef cgRef = [image CGImageForProposedRect:NULL
context:nil
hints:nil];
NSBitmapImageRep *newRep = [[NSBitmapImageRep alloc] initWithCGImage:cgRef];
[newRep setSize:[image size]]; // if you want the same resolution
NSData *pngData = [newRep representationUsingType:NSPNGFileType properties:nil];
[pngData writeToFile:path atomically:YES];
[newRep autorelease];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment