CIEdgeWork 滤镜的使用

CIEdgeWork 滤镜效果如下

滤镜效果

先看参数:

CIFilter *filter = [CIFilter filterWithName:@"CIEdgeWork"];
NSLog(@"%@ - %@", filterName, filter.attributes);
    inputImage =     {
        CIAttributeClass = CIImage;
        CIAttributeDescription = "The image to use as an input image. For filters that also use a background image, this is the foreground image.";
        CIAttributeDisplayName = Image;
        CIAttributeType = CIAttributeTypeImage;
    };
    inputRadius =     {
        CIAttributeClass = NSNumber;
        CIAttributeDefault = 3;
        CIAttributeDescription = "The thickness of the edges. The larger the value, the thicker the edges.";
        CIAttributeDisplayName = Radius;
        CIAttributeMin = 0;
        CIAttributeSliderMax = 20;
        CIAttributeSliderMin = 0;
        CIAttributeType = CIAttributeTypeDistance;
    };

所以这个滤镜除了image以外还需要以下参数:

  • inputRadius:厚度,默认值3,范围0~20

实例

代码

    CIFilter *filter = [CIFilter filterWithName:@"CIEdgeWork"];
    CIContext *context = [CIContext contextWithOptions:nil];
    NSLog(@"%@ - %@", filterName, filter.attributes);
    if (filter.attributes[kCIInputImageKey]) {
        [filter setValue:inputImage forKey:kCIInputImageKey];
        
        if (filter.attributes[kCIInputRadiusKey]) {
            NSNumber *radius = @([filter.attributes[kCIInputRadiusKey][kCIAttributeSliderMax] integerValue] / 10);
            [filter setValue:radius forKey:kCIInputRadiusKey];
        }

        CIImage *outPutImage = filter.outputImage;
        CGImageRef imageRef = [context createCGImage:outPutImage fromRect:outPutImage.extent];
        if (imageRef) {
            return [UIImage imageWithCGImage:imageRef];
        }
    }
    
    return nil;

效果

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。