Created
July 27, 2012 01:41
-
-
Save andy-cam/3185714 to your computer and use it in GitHub Desktop.
Category to resize UIImage
This file contains hidden or 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
| #pragma mark - UIImage Scaler Category | |
| @interface UIImage (scale) | |
| -(UIImage*)scaleToSize:(CGSize)size; | |
| @end | |
| @implementation UIImage (scale) | |
| -(UIImage*)scaleToSize:(CGSize)size{ | |
| UIGraphicsBeginImageContext(size); // Create a bitmap graphics context (also sets it as the current context) | |
| [self drawInRect:CGRectMake(0, 0, size.width, size.height)]; // Draw the scaled image in the current context | |
| UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext(); // Create a new image from current context | |
| UIGraphicsEndImageContext(); // Pop the current context from the stack | |
| return scaledImage; // Return our new scaled image | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment