Export/Import NSImage as ICO
I would like to save and read an ICO file. It doesnt matter if its NSImage or NSBitmapImageRep or anything. It just needs开发者_如何学编程 to be done. How could this be accomplished?
I found it out for myself. Here is my code:
NSImage *o = [[NSImage alloc] initWithContentsOfFile:path];
CGImageDestinationRef dest = CGImageDestinationCreateWithURL(
(CFURLRef)[NSURL fileURLWithPath:newPath],
(CFStringRef)@"com.microsoft.ico",
o.representations.count,
NULL);
for (NSBitmapImageRep *rep in o.representations) {
CGImageRef ref = rep.CGImage;
CGImageDestinationAddImage(dest,
ref,
NULL);
}
CGImageDestinationFinalize(dest);
精彩评论