I put the Ben code as an extension in the NS-Extensions file so that I can show any image to make it a thumbnail, for example:
UIImage *bigImage = [UIImage imageNamed:@"yourImage.png"]; UIImage *thumb = [bigImage makeThumbnailOfSize:CGSizeMake(50,50)];
Here is the .h file:
@interface UIImage (PhoenixMaster) - (UIImage *) makeThumbnailOfSize:(CGSize)size; @end
and then in the NS-Extensions.m file:
@implementation UIImage (PhoenixMaster) - (UIImage *) makeThumbnailOfSize:(CGSize)size { UIGraphicsBeginImageContextWithOptions(size, NO, UIScreen.mainScreen.scale); // draw scaled image into thumbnail context [self drawInRect:CGRectMake(0, 0, size.width, size.height)]; UIImage *newThumbnail = UIGraphicsGetImageFromCurrentImageContext(); // pop the context UIGraphicsEndImageContext(); if(newThumbnail == nil) NSLog(@"could not scale image"); return newThumbnail; } @end
PapaSmurf Apr 27 '11 at 23:05 2011-04-27 23:05
source share