Created
December 10, 2015 03:25
-
-
Save phucnm/245cc02eed0d2a8710bd to your computer and use it in GitHub Desktop.
Scale image in iOS without lose quality much - UIImage category
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
@interface UIImage (Resize) | |
- (UIImage*)scaleBy:(float)scale; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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