2010-07-10 68 views

回答

1

我为自己找到了。这是我的代码:

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); 
+0

经过一段时间使用上述解决方案,我决定我需要更多的功能,特别是自定义大小。所以我自己写了一个类,支持0到256之间的任意大小。 http://github.com/alexzielenski/ICOFamily – 2010-08-06 16:17:36