How do I recreate UIImage with lower compression in iOS?

I have code to recreate a high quality image with very low quality, but I'm a little confused by the results I see. The code is here:

NSData *compressedData = UIImageJPEGRepresentation(bigImage,0);
NSLog(@"compressedData length = %d", [compressedData length]);
self.currentImage = [UIImage imageWithData:compressedData];
NSData *dataAfterCompression = UIImageJPEGRepresentation(self.currentImage,1);
NSLog(@"dataAfterCompression length = %d", [dataAfterCompression length]);

What outputs:

2012-01-02 02:47:05.615 MyApp[349:707] compressedData length = 32671
2012-01-02 02:47:06.143 MyApp[349:707] dataAfterCompression length = 251144

Why would creating such an image with poor quality data result in such a large image?

+5
source share
3 answers

UIImageJPEGRepresentation - 2- , , 2-D . (, !) UIImageJPEGRepresentation , , "" . , , ( compressionQuality ), , ( compressionQuality ).

JPEG . compressionQuality . compressionQuality 1, , , , . . , . ", , ​​ ". , , .

+8

, Confused

0.0

NSData * compressData = UIImageJPEGRepresentation (bigImage, 0);

NSLog (@ "compressionData length =% d", [compressionData length]);

self.currentImage = [UIImage imageWithData: compressData];

* 1 *

NSData * dataAfterCompression = UIImageJPEGRepresentation (self.currentImage, 1);

NSLog (@ "dataAfterCompression length =% d", [dataAfterCompression length]);

/* NSData * UIImageJPEGR (  UIImage * ,  CGFloat compressionQuality ); */

0.0 means maximum compression and low quality

1 means minimal compression and high quality

-1
source

All Articles