Skip to content

Instantly share code, notes, and snippets.

@derektu
Last active December 12, 2015 09:49
Show Gist options
  • Save derektu/4754106 to your computer and use it in GitHub Desktop.
Save derektu/4754106 to your computer and use it in GitHub Desktop.
UIImage extension
// UIImage+UIImageExtension.h
//
#import <Foundation/Foundation.h>
@interface UIImage (UIImageExtension)
// Resample to create another image: aspect ratio is not preserved (not yet)
//
- (UIImage *)resample:(CGSize)newSize;
@end
// UIImage+UIImageExtension.m
//
#import "UIImage+UIImageExtension.h"
@implementation UIImage (UIImageExtension)
- (UIImage *)resample:(CGSize)newSize
{
UIGraphicsBeginImageContext(newSize);
[self drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment