Save the NSImage that contains the icon as a TIFF file (use NSData* tiff = [image TIFFRepresentation]; to create an NSData with a TIFF file, and then just use [tiff writeToFile:tiffFile atomically:YES]; to save it in some folder), then use NSTask to convert the TIFF file to an ICNS file using tiff2icns .
tiff2icns /Users/Me/Desktop/pic.tiff /Users/Me/Desktop/pic.icns
Now an example of the complete code (the image is an NSImage file, an icon, and iconFile is an NSString with the final icns location):
NSString* tiffFile = [NSString stringWithFormat:@"%@.tiff",iconFile]; NSData* tiff = [image TIFFRepresentation]; [tiff writeToFile:tiffFile atomically:YES]; NSTask *task = [[NSTask alloc] init]; [task setLaunchPath:@"/usr/bin/tiff2icns"]; [task setArguments:[NSArray arrayWithObjects:tiffFile, iconFile, nil]]; [task launch]; [task waitUntilExit]; [[NSFileManager defaultManager] removeItemAtPath:tiffFile error: NULL];
What is it.
source share