Skip to content
This repository has been archived by the owner on May 8, 2020. It is now read-only.

Commit

Permalink
Use iOS 4 method
Browse files Browse the repository at this point in the history
  • Loading branch information
danielctull committed Jul 7, 2012
1 parent b3fd1a2 commit 4275d97
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions DCTImageSizing/DCTImageSizing.m
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,27 +12,16 @@
@implementation UIImage (DCTImageSizing) @implementation UIImage (DCTImageSizing)


- (UIImage *)dct_imageWithSize:(CGSize)size contentMode:(UIViewContentMode)contentMode { - (UIImage *)dct_imageWithSize:(CGSize)size contentMode:(UIViewContentMode)contentMode {

CGImageRef imageRef = self.CGImage;

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, size.width, size.height, 8, 0, colorSpace, kCGImageAlphaNoneSkipLast);

CGRect rect = CGRectMake(0.0f, 0.0f, size.width, size.height);
CGContextSetFillColor(context, CGColorGetComponents([UIColor whiteColor].CGColor));
CGContextFillRect(context, rect);


CGRect imageRect = [DCTContentSizer rectForOriginalSize:self.size desiredSize:size contentMode:contentMode]; CGRect imageRect = [DCTContentSizer rectForOriginalSize:self.size desiredSize:size contentMode:contentMode];
CGContextDrawImage(context, imageRect, imageRef); UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);

CGImageRef sourceImg = CGImageCreateWithImageInRect([self CGImage], imageRect);
CGImageRef scaledImageRef = CGBitmapContextCreateImage(context); [self drawInRect:imageRect];
UIImage *scaledImage = [UIImage imageWithCGImage:scaledImageRef]; CGImageRelease(sourceImg);

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
CGColorSpaceRelease(colorSpace); UIGraphicsEndImageContext();
CGContextRelease(context);
CGImageRelease(scaledImageRef); return image;

return scaledImage;
} }


@end @end

0 comments on commit 4275d97

Please sign in to comment.