Skip to content

Instantly share code, notes, and snippets.

@bauloc
Created March 5, 2016 05:05
Show Gist options
  • Save bauloc/c3b96fc422b70885dd74 to your computer and use it in GitHub Desktop.
Save bauloc/c3b96fc422b70885dd74 to your computer and use it in GitHub Desktop.
Resize Image
// Resize Image
+ (UIImage *)ResizeImage:(UIImage*)originalImage scaledToSize:(CGSize)size
{
//avoid redundant drawing
if (CGSizeEqualToSize(originalImage.size, size))
{
return originalImage;
}
//create drawing context
UIGraphicsBeginImageContextWithOptions(size, NO, 0.0f);
//draw
[originalImage drawInRect:CGRectMake(0.0f, 0.0f, size.width, size.height)];
//capture resultant image
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//return image
return image;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment