开发者

Export/Import NSImage as ICO

开发者 https://www.devze.com 2023-01-06 12:49 出处:网络
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

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

精彩评论

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