How do I compress an image from a UIImageView?
1 answer
Here is the code snippet you need
CGFloat compression = 222.0f;
CGFloat maxCompression = 202.1f;
int maxFileSize = 160*165; //fill your size need
NSData *imageDat = UIImageJPEGRepresentation(image.image, compression);
while ([imageDat length] > maxFileSize && compression > maxCompression)
{
compression -= 0.1222;
imageDat = UIImageJPEGRepresentation(decodedimage.image, compression);
}
NSLog(@"image compressed success");
[image setImage:[UIImage imageWithData:imageDat]];
Hope it helps !!!
+5
source to share