码迷,mamicode.com
首页 > 其他好文 > 详细

截屏并高斯模糊

时间:2015-08-05 14:55:42      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:高斯模糊   截屏   模糊   高斯   ios   

//截屏获得当前的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];


}


技术分享

版权声明:本文为博主原创文章,未经博主允许不得转载。

截屏并高斯模糊

标签:高斯模糊   截屏   模糊   高斯   ios   

原文地址:http://blog.csdn.net/lu_ca/article/details/47295597

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!