Instantly share code, notes, and snippets.

Embed
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];
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