//截屏获得当前的image
- (UIImage *)imageOfView:(UIView *)view
{
UIGraphicsBeginImageContext(view.bounds.size); //currentView 当前的view
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return viewImage;
}
//高斯模糊
- (void)blur{
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
CIContext *context = [CIContext contextWithOptions:nil];
UIImage *oldImage = [self imageOfView:self.view];
CIImage *inputImage = [[CIImage alloc] initWithImage:oldImage];
// create gaussian blur filter
CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"];
[filter setValue:inputImage forKey:kCIInputImageKey];
[filter setValue:[NSNumber numberWithFloat:20.0] forKey:@"inputRadius"];
// blur image
CIImage *result = [filter valueForKey:kCIOutputImageKey];
CGImageRef cgImage = [context createCGImage:result fromRect:[result extent]];
UIImage *image = [UIImage imageWithCGImage:cgImage];
CGImageRelease(cgImage);
imageView.image = image;
NSLog(@"%f-----%f",imageView.frame.size.height,imageView.frame.size.width);
[self.view addSubview:imageView];
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/lu_ca/article/details/47295597