Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
+(UIImage *)thumbnailForImage:(UIImage *)image withSize:(CGSize)size{
CGImageRef sourceImage = [image CGImage];
const char *byteData = malloc(CGImageGetBytesPerRow(sourceImage) * 75);
if(malloc == NULL) return nil;
CGBitmapInfo info = CGImageGetBitmapInfo(sourceImage);
CGContextRef context = CGBitmapContextCreate(byteData, 75, 75,CGImageGetBitsPerComponent(sourceImage), CGImageGetBytesPerRow(sourceImage), CGImageGetColorSpace(sourceImage), info);
CGContextDrawImage(context, CGRectMake(0,0,size.width, size.height), sourceImage);
CGImageRef destImage = CGBitmapContextCreateImage(context);
UIImage *img = [[UIImage alloc] initWithCGImage:destImage];
return [img autorelease];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.