CoreImage滤镜的组合

来源:互联网 发布:windows键的用途 编辑:程序博客网 时间:2024/04/30 14:28
不同的滤镜可以组合在一起使用。
可以动态的修改滤镜组合中单个滤镜的参数来实现一种动态调整的效果。

 // 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];

0 0
原创粉丝点击