-
-
Save MarcoSero/b5b9b2837d64b32d1c92 to your computer and use it in GitHub Desktop.
Revisions
-
MarcoSero renamed this gist
Feb 6, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Krzysztof Zabłocki created this gist
Oct 25, 2012 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ + (UIImage *)decompressedImageWithImage:(UIImage *)image resizeTo:(CGSize)targetSize { CGImageRef imageRef = image.CGImage; CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(imageRef); BOOL sameSize = NO; if (CGSizeEqualToSize(targetSize, CGSizeMake(CGImageGetWidth(imageRef), CGImageGetHeight(imageRef)))) { targetSize = CGSizeMake(1, 1); sameSize = YES; } size_t imageWidth = (size_t)targetSize.width; size_t imageHeight = (size_t)targetSize.height; CGContextRef context = CGBitmapContextCreate(NULL, imageWidth, imageHeight, 8, // Just always return width * 4 will be enough imageWidth * 4, // System only supports RGB, set explicitly colorSpace, // Makes system don't need to do extra conversion when displayed. alphaInfo | kCGBitmapByteOrder32Little); CGColorSpaceRelease(colorSpace); if (!context) { return nil; } CGRect rect = (CGRect){CGPointZero, {imageWidth, imageHeight}}; CGContextDrawImage(context, rect, imageRef); if (sameSize) { CGContextRelease(context); return image; } CGImageRef decompressedImageRef = CGBitmapContextCreateImage(context); CGContextRelease(context); UIImage *decompressedImage = [[UIImage alloc] initWithCGImage:decompressedImageRef scale:image.scale orientation:image.imageOrientation]; CGImageRelease(decompressedImageRef); return decompressedImage; }