Skip to content
Browse files

Use iOS 4 method

  • Loading branch information...
1 parent b3fd1a2 commit 4275d97dd014ce7d71f2b1dfa198dccee9de175c @danielctull committed Jul 7, 2012
Showing with 8 additions and 19 deletions.
  1. +8 −19 DCTImageSizing/DCTImageSizing.m
View
27 DCTImageSizing/DCTImageSizing.m
@@ -12,27 +12,16 @@
@implementation UIImage (DCTImageSizing)
- (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];
- CGContextDrawImage(context, imageRect, imageRef);
-
- CGImageRef scaledImageRef = CGBitmapContextCreateImage(context);
- UIImage *scaledImage = [UIImage imageWithCGImage:scaledImageRef];
-
- CGColorSpaceRelease(colorSpace);
- CGContextRelease(context);
- CGImageRelease(scaledImageRef);
-
- return scaledImage;
+ UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
+ CGImageRef sourceImg = CGImageCreateWithImageInRect([self CGImage], imageRect);
+ [self drawInRect:imageRect];
+ CGImageRelease(sourceImg);
+ UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
+ UIGraphicsEndImageContext();
+
+ return image;
}
@end

0 comments on commit 4275d97

Please sign in to comment.
Something went wrong with that request. Please try again.