0
我想保存并阅读ICO文件。它没关系,如果它的NSImage或NSBitmapImageRep或任何东西。它只是需要完成。这怎么可能完成?导出/导入NSImage为ICO
我想保存并阅读ICO文件。它没关系,如果它的NSImage或NSBitmapImageRep或任何东西。它只是需要完成。这怎么可能完成?导出/导入NSImage为ICO
我为自己找到了。这是我的代码:
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到256之间的任意大小。 http://github.com/alexzielenski/ICOFamily – 2010-08-06 16:17:36