Skip to content

Instantly share code, notes, and snippets.

@phucnm
Created December 10, 2015 03:25
Show Gist options
  • Save phucnm/245cc02eed0d2a8710bd to your computer and use it in GitHub Desktop.
Save phucnm/245cc02eed0d2a8710bd to your computer and use it in GitHub Desktop.
Scale image in iOS without lose quality much - UIImage category
#import <UIKit/UIKit.h>
@interface UIImage (Resize)
- (UIImage*)scaleBy:(float)scale;
@end
#import "UIImage+Resize.h"
@implementation UIImage (Resize)
- (UIImage*)scaleBy:(float)scale
{
CGSize size = CGSizeMake(self.size.width * scale, self.size.height * scale);
UIGraphicsBeginImageContextWithOptions(size, YES, 0.0);
[self drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *imageCopy = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return imageCopy;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment