Objective-C - Convert image to icns

I am trying to create an application for Mac OS X that converts an image type to an icns file. I am wondering how I can start doing this. Any suggestions would be nice!

Thanks,

Kevin

0
source share
3 answers

Use the CGImageSource APIs (e.g. CGImageSourceCreateWithURL , CGImageSourceCreateImageAtIndex ) to load each image into a CGImageRef . Then use the CGImageDestination APIs (e.g. CGImageDestinationCreateWithURL , CGImageDestinationAddImage , CGImageDestinationFinalize ) to combine the entire number of images into a single icon file. The third parameter of CGImageDestinationCreateWithURL will be kUTTypeAppleICNS .

+3
source

1 Create a folder named icon.iconset .
2 Add one or more of the following images to the folder:

 icon_16x16.png icon_16x16@2x.png icon_32x32.png icon_32x32@2x.png icon_128x128.png icon_128x128@2x.png icon_256x256.png icon_256x256@2x.png icon_512x512.png icon_512x512@2x.png 

3 Run this command and icon.icns will be created.

 iconutil -c icns icon.iconset 

http://developer.apple.com/library/mac/#documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Optimizing/Optimizing.html#//apple_ref/doc/uid/TP40012302-CH7-SW2

+1
source

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.

0
source

All Articles