滤镜简单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.     }  
原文地址:https://www.cnblogs.com/isItOk/p/4873171.html