gpt4 book ai didi

cocoa - 将 NSImage 导出/导入为 ICO

转载 作者:行者123 更新时间:2023-12-03 18:04:44 25 4
gpt4 key购买 nike

我想保存并读取 ICO 文件。 NSImage 或 NSBitmapImageRep 或其他什么都没关系。它只是需要完成。如何实现这一点?

最佳答案

我自己发现了。这是我的代码:

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

关于cocoa - 将 NSImage 导出/导入为 ICO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3219993/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com