CoreImage滤镜的组合

不同的滤镜可以组合在一起使用。
可以动态的修改滤镜组合中单个滤镜的参数来实现一种动态调整的效果。

 // 0. 导入CIImage图片
    CIImage *ciImage = [[CIImage alloc] initWithImage:[UIImage imageNamed:@"demo"]];
    
    // 1. 创建出Filter滤镜
    CIFilter *filterOne = [CIFilter filterWithName:@"CIPixellate"];
    
    [filterOne setValue:ciImage
              forKey:kCIInputImageKey];
    
    [filterOne setDefaults];
    
    CIImage *outImage = [filterOne valueForKey:kCIOutputImageKey];
    
    CIFilter *filterTwo = [CIFilter filterWithName:@"CIHueAdjust"];
    [filterTwo setValue:outImage
                 forKey:kCIInputImageKey];
    
    [filterTwo setDefaults];
    
    [filterTwo setValue:@(3.14)
                 forKey:kCIInputAngleKey];
    
    CIImage *outputImage = [filterTwo valueForKey:kCIOutputImageKey];
    
    // 2. 用CIContext将滤镜中的图片渲染出来
    CIContext *context = [CIContext contextWithOptions:nil];
    
    CGImageRef cgImage = [context createCGImage:outputImage
                                       fromRect:[outImage extent]];
    
    // 3. 导出图片
    UIImage *showImage = [UIImage imageWithCGImage:cgImage];
    
    CGImageRelease(cgImage);
    
    // 4. 加载出来
    UIImageView *imageView = [[UIImageView alloc] initWithImage:showImage];
    imageView.center       = self.view.center;
    [self.view addSubview:imageView];

你可能感兴趣的:(iOS技术,【iOS开发,深入浅出学习系列】,CoreImage,图片,uiimage,iOS)