zoukankan      html  css  js  c++  java
  • CIFilter (模糊图片)

     //使用模糊图片

    #import "ViewController.h"

    @interface ViewController ()

    @end

    @implementation ViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        

        UIImage *image = [UIImage imageNamed:@"qiaodan"];

        

        //coreImage

        CIImage *ciImage = [[CIImage alloc] initWithImage:image];

        CIFilter *blurFilter = [CIFilter filterWithName:@"CIGaussianBlur"];

        //设置模糊程度

        [blurFilter setValue:@(2) forKey:@"inputRadius"];

        //查询滤镜设置参数的信息

        NSLog(@"%@",[blurFilter attributes]);

        //将图片输入到滤镜中

        [blurFilter setValue:ciImage forKey:kCIInputImageKey];

        //将处理好的图片输出

        CIImage *outCiImage = [blurFilter valueForKey:kCIOutputImageKey];

        

        //CIContext

        CIContext *context = [CIContext contextWithOptions:nil];

        //获取CGImage句柄

        CGImageRef outCGImage = [context createCGImage:outCiImage fromRect:[outCiImage extent]];

        //最终获取到图片

        UIImage *blurImage = [UIImage imageWithCGImage:outCGImage];

        //释放CGImage句柄

        CGImageRelease(outCGImage);

            

        //图片初始化

        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 640/2.f, 640/2.f)];

        imageView.image = blurImage;

        imageView.center = self.view.center;

        [self.view addSubview:imageView];   

        

        // Do any additional setup after loading the view, typically from a nib.

    }

    - (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

    @end

  • 相关阅读:
    Mysql一些复杂的语句
    Tomcat部署记事
    [转]Java中的事务
    Junit单元测试笔记
    Mysql之执行计划
    当产品部署出现问题时
    CSS之绝对定位那些事
    CSS之浮动那些事
    Tomcat一些小事
    NEC的学习笔记
  • 原文地址:https://www.cnblogs.com/jiurong001/p/5205359.html
Copyright © 2011-2022 走看看