I have tried image resize plugin to compress image in my app. But it reduces the clarity and it doesn't look good. Can anyone please tell me any other solution to compress image dynamically in my iPhone application.
#import <Foundation/Foundation.h>
@interface UIImage (Resize)
- (UIImage*)scaleToSize:(CGSize)size;
@end
#import "UIImage+Resize.h"
// Put this in UIImageResizing.m
@implementation UIImage (Resize)
- (UIImage*)scaleToSize:(CGSize)size {
UIGraphicsBeginImageContext(size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, 0.0, size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, size.width, size.height), self.CGImage);
UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return scaledImage;
}
@end