zoukankan      html  css  js  c++  java
  • 滤镜简单demo(转,供参考)

    1. NSURL *iamgeUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"default" ofType:@"png"]];  
    2.     CIContext *context = [CIContext contextWithOptions:nil];  
    3.     CIImage *image = [CIImage imageWithContentsOfURL:iamgeUrl];  
    4.       
    5.     CIFilter *filter = [CIFilter filterWithName:@"CISepiaTone"];  
    6.     [filter setValue:image forKey:kCIInputImageKey];  
    7.     [filter setValue:[NSNumber numberWithFloat:0.5] forKey: @"inputIntensity"];  
    8.       
    9.     CIImage *result = [filter valueForKey:kCIOutputImageKey];  
    10.     CGImageRef outImage = [context createCGImage: result fromRect:[result extent]];  
    11.     UIImage * blurImage = [UIImage imageWithCGImage:outImage];  
    12.     _imageBG = [[UIImageView alloc] initWithImage:blurImage];  
    13.     _imageBG.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);  
    14.       
    15.     [self.view addSubview:self.imageBG];  

    CIImage 保存图像数据的类,可以通过UIImage,图像文件或者像素数据来创建。

    CIFilter 滤镜类,这个框架中对图片属性进行细节处理的类。它对所有的像素进行操作,用一些键-值设置来决定具体操作的程度。

    CIContext 上下文类,如CoreGraphics以及CoreData中的上下文用于处理绘制渲染以及处理托管对象一样,CoreImage的上下文也是实现对图像处理的具体对象。

    打印所有的滤镜信息:

    1. //打印所有过滤器信息  
    2.     NSArray *properties = [CIFilter filterNamesInCategory:kCICategoryBuiltIn];  
    3.     NSLog(@"FilterName: %@", properties);  
    4.     for (NSString *filterName in properties) {  
    5.         CIFilter *fltr = [CIFilter filterWithName:filterName];  
    6.         NSLog(@"%@: %@", filterName, [fltr attributes]);  
    7.     }  
  • 相关阅读:
    不要在构造中做太多事情,不然有时候会出现有意思的代码~
    对称加密和非对称加密
    关于WebAPI安全认证的问题
    Dojo和jQuery区别
    跨域访问解决方案:JSONP
    MyEclipse中提示SpringMVC的XML配置文件出错解决方法
    什么是跨域请求
    Hadoop的初步理解
    数据库读写分离的初步理解
    前端渲染和后端渲染
  • 原文地址:https://www.cnblogs.com/isItOk/p/4873171.html
Copyright © 2011-2022 走看看