Compress image, without quality loss using Objective C code:
NSData *imageData1= nil;
imageData1 =UIImageJPEGRepresentation([self compressForUpload:self.imageView.image scale:1.0], 0.8);
-(UIImage *)compressForUpload:(UIImage *)original scale:(CGFloat)scale
{
CGSize originalSize = original.size;
CGSize newSize = CGSizeMake(originalSize.width *scale, originalSize.height *scale);
UIGraphicsBeginImageContext(newSize);
[original drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage* compressedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return compressedImage;
}
No comments:
Post a Comment