Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compress image size using UIImagePNGRepresentation - iOS?

I'm using UIImagePNGRepresentation to save an image. The result image is of size 30+ KB and this is BIG in my case.

I tried using UIImageJPEGRepresentation and it allows to compress image, so image saves in < 5KB size, which is great, but saving it in JPEG gives it white background, which i don't want (my image is circular, so I need to save it with transparent background).

How can I compress image size, using UIImagePNGRepresentation?

like image 985
Hyder Avatar asked Feb 11 '16 19:02

Hyder


1 Answers

PNG uses lossless compression, that's why UIImagePNGRepresentation does not accept compressionQuality parameter like UIImageJPEGRepresentation does. You might get a bit smaller PNG file with different tools, but nothing like with JPEG.

like image 169
Filip Radelic Avatar answered Oct 21 '22 20:10

Filip Radelic