Created
October 11, 2011 14:22
-
-
Save dcai/1278207 to your computer and use it in GitHub Desktop.
shrinkImage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static UIImage *shrinkImage(UIImage *original, CGSize size) { | |
CGFloat scale = [UIScreen mainScreen].scale; | |
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); | |
CGContextRef context = CGBitmapContextCreate(NULL, size.width * scale, | |
size.height * scale, 8, 0, colorSpace, kCGImageAlphaPremultipliedFirst); | |
CGContextDrawImage(context, | |
CGRectMake(0, 0, size.width * scale, size.height * scale), | |
original.CGImage); | |
CGImageRef shrunken = CGBitmapContextCreateImage(context); | |
UIImage *final = [UIImage imageWithCGImage:shrunken]; | |
CGContextRelease(context); | |
CGImageRelease(shrunken); | |
return final; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment