Skip to content

Instantly share code, notes, and snippets.

@keefo
Created July 10, 2013 04:46
Show Gist options
  • Save keefo/5963546 to your computer and use it in GitHub Desktop.
Save keefo/5963546 to your computer and use it in GitHub Desktop.
- (NSImage *)resizeTo:(NSSize)newsize
{
NSImage *resizedImage = [[NSImage alloc] initWithSize:newsize];
NSSize originalSize = [self size];
[resizedImage lockFocus];
[self drawInRect: NSMakeRect(0, 0, newsize.width, newsize.height) fromRect: NSMakeRect(0, 0, originalSize.width, originalSize.height) operation: NSCompositeSourceOver fraction: 1.0];
[resizedImage unlockFocus];
#if __has_feature(objc_arc)
return resizedImage;
#else
return [resizedImage autorelease];
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment