Library for PNG compression at runtime on iOS

I need to be able to compress PNG files at runtime, but cannot find any libraries ready for iOS that can do this. JPEG is not very suitable for me, because I need an alpha channel that provides PNG, but JPEG is not. Turning PNG into something that I can use in my iOS project probably goes beyond my skill set / knowledge when it comes to C.

Just to be extra-clear, I need to do this at runtime, not at compile time.

+8
ios image-processing png image-compression
source share
3 answers

Try ImageIO. See ImageIO Programming Guide

+3
source share

If you really have no other way, you can use UIImagePNGRepresentation so that it UIImagePNGRepresentation a thinner png file:

 // 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]; 

And then see if the new image is different or not. This method works on mac: only opening PNG files and exporting them to another PNG file can reduce its size.

+1
source share

All Articles