用于iOS上运行时PNG压缩的库

时间:2012-03-19 22:38:17

标签: ios image-processing png image-compression

我需要能够在运行时压缩PNG文件,但找不到任何可以做到这一点的iOS就绪的库。 JPEG确实不适合我,因为我需要PNG提供的Alpha通道,而JPEG则不需要。将PNG粉碎变成我可以在我的iOS项目中使用的东西可能超出了我在C语言中的技能/知识。

为了更清楚,我需要在运行时执行此操作,而不是编译时。

3 个答案:

答案 0 :(得分:3)

尝试ImageIO。见ImageIO Programming Guide

答案 1 :(得分:1)

答案 2 :(得分:1)

如果你真的没有别的办法,也许你可以使用UIImagePNGRepresentation来保存更薄的png文件:

// load image from the one you created
UIImage *image = [UIImage imageNamed:@"your image name"];
// give it a new PNG representation from the API
NSData *pngImage = UIImagePNGRepresentation(image);
//save it to another place
NSError *error = nil;
[pngImage writeToFile:@"your path" options:NSDataWritingAtomic error:&error];

然后查看新图像是否更薄。这个方法适用于mac:只需打开PNG文件并将它们导出到另一个PNG文件就可以减小它的大小。