cocoaimagemacosfilensimage

How to save a NSImage as a new file


How can I save a NSImage as a new file (png, jpg, ...) in a certain directory?


Solution

  • Do something like this:

    NSBitmapImageRep *imgRep = [[image representations] objectAtIndex: 0];
    NSData *data = [imgRep representationUsingType: NSPNGFileType properties: nil];
    [data writeToFile: @"/path/to/file.png" atomically: NO];