好的,这就是我想要的:
- 拿
NSImage
一些 - 将它们添加到
ICNS
文件中 - 保存
这是我到目前为止所做的(纯粹作为测试):
- (CGImageRef)refFromImage:(NSImage*)img
{
CGImageSourceRef source;
source = CGImageSourceCreateWithData((CFDataRef)[img TIFFRepresentation], NULL);
CGImageRef maskRef = CGImageSourceCreateImageAtIndex(source, 0, NULL);
return maskRef;
}
- (void)awakeFromNib
{
NSImage* img1 = [NSImage imageNamed:@"image1"];
NSImage* img2 = [NSImage imageNamed:@"image2"];
NSLog(@"%@",img1);
CGImageRef i1 = [self refFromImage:img1];
CGImageRef i2 = [self refFromImage:img2];
NSURL *fileURL = [NSURL fileURLWithPath:[@"~/Documents/final.icns" stringByExpandingTildeInPath]];
CGImageDestinationRef dr = CGImageDestinationCreateWithURL((__bridge CFURLRef)fileURL, kUTTypeAppleICNS , 1, NULL);
CGImageDestinationAddImage(dr, i1, NULL);
CGImageDestinationAddImage(dr, i2, NULL);
/* Even tried adding 'multiple' times
CGImageDestinationAddImage(dr, i1, NULL);
CGImageDestinationAddImage(dr, i2, NULL);
CGImageDestinationAddImage(dr, i1, NULL);
CGImageDestinationAddImage(dr, i2, NULL);
*/
CGImageDestinationFinalize(dr);
CFRelease(dr);
}
但是,它仍然不断抛出错误:
ImageIO:CGImageDestinationFinalize 图像目的地没有足够的图像
我的代码有什么问题?
我已经看过下面的答案,但仍然没有: