Created
January 7, 2009 20:10
-
-
Save stevestreza/44393 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+(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