开发者

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜