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

CoreImage的模糊滤镜

时间:2015-08-06 14:53:22      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:

    //1.原始图片
    UIImage * image = [UIImage imageNamed:@"1.jpg"];
    
    /****************core image******************/
    //a.图片
    CIImage * ciImage = [[CIImage alloc] initWithImage:image];
    //b.滤镜
    CIFilter * ciFilter = [CIFilter filterWithName:@"CIGaussianBlur"];
    NSLog(@"%@",[ciFilter attributes]);
    //设置滤镜的模糊程度,默认是10
    [ciFilter setValue:@(10) forKey:@"inputRadius"];
    //将图片放到滤镜中
    [ciFilter setValue:ciImage forKey:kCIInputImageKey];
    //输出图片
    CIImage * outImage = [ciFilter valueForKey:kCIOutputImageKey];
    //c.获取CGImage的句柄
    CIContext * context = [CIContext contextWithOptions:nil];
    CGImageRef outCGImage = [context createCGImage:outImage fromRect:[outImage extent]];
    UIImage * blurImage = [UIImage imageWithCGImage:outCGImage];
    CGImageRelease(outCGImage);
    
    /********************************************/
    //2.初始化imageView
    UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 20, 320, 200)];
    imageView.image = blurImage;
    [self.view addSubview:imageView];

 

CoreImage的模糊滤镜

标签:

原文地址:http://www.cnblogs.com/benbenzhu/p/4707915.html

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