views:

40

answers:

1

Hi everyone, I would like to save and read an ICO file. It doesnt matter if its NSImage or NSBitmapImageRep or anything. It just needs to be done. How could this be accomplished?

A: 

I found it out for myself. Here is my code:

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);
Alex Zielenski
After a while of using the above solution, i decided I needed more features, specifically custom sizes. So i wrote a class myself that supports any size between 0 and 256.http://github.com/alexzielenski/ICOFamily
Alex Zielenski