Skip to content

Instantly share code, notes, and snippets.

@andy-cam
andy-cam / gist:3185714
Created July 27, 2012 01:41
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