Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reduce camera/photo library image file size for less than 100 KB in iphone

I want to reduce image file size that take from UIImagePickerController . I use this method

NSData *imageData = UIImageJPEGRepresentation(image, 0.1);

but it reduce 2.2 MB image file size to 300 KB I want my image file size become less than 100 KB.

like image 578
Poooyak Avatar asked Dec 29 '12 19:12

Poooyak


People also ask

How do I reduce 100 KB of a photo?

How to reduce the image size in KB/MB? To reduce the image size in KB or MB online, first upload it to ResizePixel's website. Enter a desired file size and select the corresponding unit of measurement (KB or MB). Then proceed to Download page to get the image file.


2 Answers

Apple's docs state:

The quality of the resulting JPEG image, expressed as a value from 0.0 to 1.0. The value 0.0 represents the maximum compression (or lowest quality) while the value 1.0 represents the least compression (or best quality).

And since the compression quality is a CGFloat, it supports decimal places beyond the tenths place. That being said, try:

NSData *imageData = UIImageJPEGRepresentation(image, 0.032);
like image 145
Mick MacCallum Avatar answered Sep 21 '22 13:09

Mick MacCallum


Easiest way to reduce image size in kilos is to reduce the size in pixels! Scale it smaller:

CGFloat scaleSize = 0.2f;
UIImage *smallImage = [UIImage imageWithCGImage:image.CGImage
                      scale:scaleSize
                      orientation:image.imageOrientation];
like image 28
JOM Avatar answered Sep 19 '22 13:09

JOM