Created
June 14, 2015 02:20
-
-
Save Aufree/902f1576c58874db01ba 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
@implementation ViewController | |
- (void)viewDidLoad{ | |
_showCoverImage.contentMode = UIViewContentModeScaleAspectFit; | |
_showCoverImage.image = [self imageWithBlurredImageWithImage:_showCoverImage.image andBlurInsetFromBottom: 200 withBlurRadius:3]; | |
} | |
- (UIImage*)imageWithBlurredImageWithImage:(UIImage*)image andBlurInsetFromBottom:(CGFloat)bottom withBlurRadius:(CGFloat)blurRadius{ | |
UIGraphicsBeginImageContext(image.size); | |
CGContextRef context = UIGraphicsGetCurrentContext(); | |
CGContextScaleCTM(context, 1, -1); | |
CGContextTranslateCTM(context, 0, -image.size.height); | |
CGContextDrawImage(context, CGRectMake(0, 0, image.size.width, image.size.height), image.CGImage); | |
CGContextDrawImage(context, CGRectMake(0, 0, image.size.width, bottom), [self blurImage: image withBottomInset: bottom blurRadius: blurRadius].CGImage); | |
image = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
return image; | |
} | |
- (UIImage*)blurImage:(UIImage*)image withBottomInset:(CGFloat)inset blurRadius:(CGFloat)radius{ | |
image = [UIImage imageWithCGImage: CGImageCreateWithImageInRect(image.CGImage, CGRectMake(0, image.size.height - inset, image.size.width,inset))]; | |
CIImage *ciImage = [CIImage imageWithCGImage:image.CGImage]; | |
CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"]; | |
[filter setValue:ciImage forKey:kCIInputImageKey]; | |
[filter setValue:@(radius) forKey:kCIInputRadiusKey]; | |
CIImage *outputCIImage = filter.outputImage; | |
CIContext *context = [CIContext contextWithOptions:nil]; | |
return [UIImage imageWithCGImage: [context createCGImage:outputCIImage fromRect:ciImage.extent]]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment