Objective-C – Convert an image to icns
I am trying to create an app for the Mac OS X that will convert an image type to an icns file. I’m wondering how I can get started on doing so. Any suggestions would be nice!
- Why is != NSClassFromString(NSStringFromClass()) on OS X?
- How to retrieve the iPhone's locale setting
- How to update Xcode 3.2.5 to 4.4.1 version in mac leopard?
- Unable to use xcodebuild on Mavericks with Command Line Tools installed
- CGEventPostToPSN - How to send keys with different keyboard locales?
- NSUserDefaults not working on Xcode beta with Watch OS2
3 Solutions Collect From Internet About “Objective-C – Convert an image to icns”
Use CGImageSource APIs (e.g.,
CGImageSourceCreateImageAtIndex) to load each image into a
CGImageRef. Then use CGImageDestination APIs (e.g.,
CGImageDestinationFinalize) to combine however many images you have into one icon file. The 3rd parameter of
CGImageDestinationCreateWithURL would be
1 Create a folder named
2 Add one or more of the following images to the folder:
icon_16x16.png email@example.com icon_32x32.png firstname.lastname@example.org icon_128x128.png email@example.com icon_256x256.png firstname.lastname@example.org icon_512x512.png email@example.com
3 Run this command and
icon.icns will be created.
iconutil -c icns icon.iconset
Save the NSImage which contains the icon as a TIFF file (use
NSData* tiff = [image TIFFRepresentation]; to create a NSData with the 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 /Users/Me/Desktop/pic.tiff /Users/Me/Desktop/pic.icns
Now, an example of the complete code (image is a NSImage file the icon, and iconFile is an NSString with the final location of the icns):
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];
And that’s it.
- Detect and use optional external C library at runtime in Objective-C
- How do I change the color of the text in a UIPickerView under iOS 7?
- Calculate the size in bytes of a Swift String
- UIAlertView causes crash in Release mode
- Why use optional binding?
- CMSampleBufferRef to bitmap?
- Encoding NSAttributedString Throws Error
- When to use UIKIT_EXTERN vs just extern
- How to display the iPhone/iPad keyboard over a full screen OpenGL ES app
- “ convention
- How to assure that operations in an OperationQueue are finished one after another
- ToolBar between UINavigationBar and UITableView?
- Main Menu In Swift
- Transliterate/transpose the characters in the NSString
- iOS HTTPS requests 101