此代碼(source
是NSMutableArray
與NSImage
對象:ImageIO的錯誤時創建文件ICNS
NSURL *fileURL = [NSURL fileURLWithPath:aPath]; CGImageDestinationRef dr = CGImageDestinationCreateWithURL((CFURLRef)fileURL, kUTTypeAppleICNS, 1, NULL); for (NSImage *img in source) { NSLog(@"%@",img); CGImageRef i1 = [img CGImageForProposedRect:NULL context:nil hints:nil]; CGImageDestinationAddImage(dr, i1, NULL); } CGImageDestinationFinalize(dr); CFRelease(dr);
導致下面的輸出:
2012-12-26 13: 48:57.682 Eicon [1131:1b0f] | NSImage 0x1025233b0 Size = {11.52,11.52} Reps =( 「NSBitmapImageRep 0x10421fc30 Size = {11.52,11.52} ColorSpace =(尚未加載)BPS = 8 BPP = (尚未加載)像素= 1024×1024阿爾法= NO平面= NO格式=(尚未加載)CurrentBacking =零(斷層)CGImageSource = 0x104221170"
(...)< - 這裏的其他NSImage中實例記錄。
ImageIO:| ERROR | CGImageDestinationFinalize圖像目標沒有足夠的圖像
任何想法,爲什麼它,並在最後的錯誤結束? (順便說一句,我想過使用IconFamily,但它使用的很多方法已被棄用)。
編輯:也許它會是提到我用它來生成圖像的代碼更重要的是,我不會感到驚訝,如果該代碼有問題(我是小白):
// Get images
[source removeAllObjects];
NSSize sizes[10];
sizes[0] = NSMakeSize(1024,1024);
sizes[1] = NSMakeSize(512,512);
sizes[2] = NSMakeSize(512,512);
sizes[3] = NSMakeSize(256,256);
sizes[4] = NSMakeSize(256,256);
sizes[5] = NSMakeSize(128,128);
sizes[6] = NSMakeSize(64,64);
sizes[7] = NSMakeSize(32,32);
sizes[8] = NSMakeSize(32,32);
sizes[9] = NSMakeSize(16,16);
for (int i=0 ; i<10 ; i++) {
if ([[NSUserDefaults standardUserDefaults] boolForKey:[NSString stringWithFormat:@"Size%i",i+1]]) {
NSBitmapImageRep *srcimg = [[NSBitmapImageRep alloc] initWithData:[NSData dataWithContentsOfFile:aFile]];
[srcimg setPixelsHigh:sizes[i].height];
[srcimg setPixelsWide:sizes[i].width];
NSImage *newimg = [[NSImage alloc] initWithSize:NSZeroSize];
[newimg addRepresentation:srcimg];
if (![newimg isValid]) {
[delegate error:@"Invalid file."];
}
else [source addObject:newimg];
}
}
如果你記錄你的CGImageRef怎麼辦? – JWWalker
'-refFromImage:'做什麼?它是否返回非零? – paulmelnikow
請編輯您的問題以包含您的'refFromImage:'代碼。 –