Question

I'm wondering how to save a CGImageRef as a palette-based PNG-8 file.

I have the following code for PNG-24:

CFURLRef url = (CFURLRef)[[NSURL alloc] initFileURLWithPath:path];

CGImageDestinationRef destination = CGImageDestinationCreateWithURL(url, kUTTypePNG, 1, NULL);
CGImageDestinationAddImage(destination, image, properties);
CGImageDestinationFinalize(destination);

Looking to convert this to PNG-8 now. If I do need to use libpng, how would you rewrite this?

Was it helpful?

Solution

Hmm, no answers :) I believe the solution may be to use libpng but I haven't tried it yet. I'll mark this as the accepted answer for now, but if anyone can offer a good tip I'll gladly change it over!

Thanks.

Edit:

I ended up hacking apart https://github.com/pornel/pngquant to get it to accept CGImageRefs, and save PNG-8 files. It wasn't pretty. In the end, I actually switched to GIF (kUTTypeGIF) which ran a lot faster in my tests.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top