Skip to content

Instantly share code, notes, and snippets.

@DrustZ
Created August 5, 2015 13:02
Show Gist options
  • Save DrustZ/147001e75251cb6d7d4b to your computer and use it in GitHub Desktop.
Save DrustZ/147001e75251cb6d7d4b to your computer and use it in GitHub Desktop.
IOS function - resize a UIimage(in C style) refer to http://stackoverflow.com/questions/3177579/displaying-images-in-fix-size
UIImage* resizeImageToSize(UIImage* image, CGSize size)
{
UIGraphicsBeginImageContext(size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
//Account for flipped coordspace
CGContextTranslateCTM(ctx, 0.0, size.height);
CGContextScaleCTM(ctx, 1.0, -1.0);
CGContextDrawImage(ctx,CGRectMake(0.0f, 0.0f, size.width, size.height), image.CGImage);
UIImage* scaled = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return scaled;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment