OK, this is what I want:
- Take some
NSImage s - Add them to the
ICNS file - Save
This is what I have done so far (purely as a test):
- (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); CGImageDestinationFinalize(dr); CFRelease(dr); }
But he still continues to throw an error:
ImageIO: CGImageDestinationFinalize image destination does not have enough images
What is wrong with my code?
I looked at the answers below, but still nothing:
source share