好的,这就是我想要的:
NSImage
s 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图像目标 没有足够的图像
我的代码出了什么问题?
我已经看过下面的答案,但仍然没有:
答案 0 :(得分:4)
您可以使用IconFamily。
IconFamily是Mac OS X Carbon的Cocoa / Objective-C包装器 API的“图标系列”数据类型。它的主要目的是启用Cocoa 应用程序可以轻松地从NSImage创建自定义文件图标 实例,从而利用Mac OS X的高分辨率RGBA “缩略图”图标格式提供丰富详细的缩略图预览 文件的内容。
NSImage *mImage = [[NSImage alloc] initWithContentsOfFile:@"/Users/Username/Desktop/WhiteTiger.jpg"];
IconFamily *fam = [IconFamily iconFamilyWithThumbnailsOfImage:mImage];
[fam writeToFile:@"/Users/Username/Desktop/WhiteTiger.icns"];