Skip to content

Instantly share code, notes, and snippets.

@motoishmz
Created August 9, 2013 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save motoishmz/6192668 to your computer and use it in GitHub Desktop.
Save motoishmz/6192668 to your computer and use it in GitHub Desktop.
- (UIImage *)resize:(UIImage *)src
{
UIImage *newImage;
CGFloat width = 0.0;
CGFloat height = 0.0;
if (src.size.width > SCREEN_BOUNDS.size.width)
{
width = SCREEN_BOUNDS.size.width;
height = src.size.height * (SCREEN_BOUNDS.size.width / src.size.width);
}
if (height > SCREEN_BOUNDS.size.height)
{
width = width * (SCREEN_BOUNDS.size.height / height);
height = SCREEN_BOUNDS.size.height;
}
CGSize previewSize = CGSizeMake(width, height);
UIGraphicsBeginImageContext(previewSize);
{
[src drawInRect:CGRectMake(0, 0, previewSize.width, previewSize.height)];
newImage = UIGraphicsGetImageFromCurrentImageContext();
}
UIGraphicsEndImageContext();
return newImage;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment