Created
          November 11, 2013 06:59 
        
      - 
      
- 
        Save Moligaloo/7409049 to your computer and use it in GitHub Desktop. 
    Save NSImage to png file
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | + (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