我想知道如何将CGImageRef保存为基于调色板的PNG-8文件。
我有以下针对PNG-24的代码:
CFURLRef url = (CFURLRef)[[NSURL alloc] initFileURLWithPath:path];
CGImageDestinationRef destination = CGImageDestinationCreateWithURL(url, kUTTypePNG, 1, NULL);
CGImageDestinationAddImage(destination, image, properties);
CGImageDestinationFinalize(destination);希望现在将其转换为PNG-8。如果我确实需要使用libpng,你会如何重写它?
发布于 2013-06-25 14:38:14
嗯,没有答案:)我相信解决方案可能是使用libpng,但我还没有尝试过。我会把这个标记为目前公认的答案,但如果有人能提供一个好的建议,我会很乐意改变它!
谢谢。
编辑:
我最终破解了https://github.com/pornel/pngquant,让它接受CGImageRefs,并保存PNG-8文件。不是很漂亮。最后,我实际上切换到了GIF (kUTTypeGIF),它在我的测试中运行得更快。
https://stackoverflow.com/questions/17158111
复制相似问题