Skip to content

Instantly share code, notes, and snippets.

@sundeepgupta
Last active August 29, 2015 14:13
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 sundeepgupta/31e51dbdb5b544f4a453 to your computer and use it in GitHub Desktop.
Save sundeepgupta/31e51dbdb5b544f4a453 to your computer and use it in GitHub Desktop.
Resizing UIImage using a CGBitmapContext
CGImageRef imageRef = image.CGImage;
CGSize size = CGSizeMake(110, 110); //From storyboard.
CGRect frame = CGRectMake(0, 0, size.width, size.height);
CGContextRef context = CGBitmapContextCreate(nil, size.width, size.height, CGImageGetBitsPerComponent(imageRef), CGImageGetBytesPerRow(imageRef), CGImageGetColorSpace(imageRef), CGImageGetBitmapInfo(imageRef));
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
CGContextDrawImage(context, frame, imageRef);
CGImageRef scaledImageRef = CGBitmapContextCreateImage(context);
UIImage *scaledImage = [UIImage imageWithCGImage:scaledImageRef];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment