Skip to content

Instantly share code, notes, and snippets.

@andy-cam
Created July 27, 2012 01:41
Show Gist options
  • Select an option

  • Save andy-cam/3185714 to your computer and use it in GitHub Desktop.

Select an option

Save andy-cam/3185714 to your computer and use it in GitHub Desktop.
Category to resize UIImage
#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