Skip to content

Instantly share code, notes, and snippets.

@stevestreza
Created January 7, 2009 20:10
Show Gist options
  • Save stevestreza/44393 to your computer and use it in GitHub Desktop.
Save stevestreza/44393 to your computer and use it in GitHub Desktop.
+(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];
CGImageRelease(destImage);
CGContextRelease(context);
free(byteData);
return [img autorelease];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment