CIEdges 滤镜的使用

CIEdges 滤镜效果如下

CIEdges 滤镜的使用_第1张图片
滤镜效果

先看参数:

CIFilter *filter = [CIFilter filterWithName:@"CIEdges"];
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;
    };
    inputIntensity =     {
        CIAttributeClass = NSNumber;
        CIAttributeDefault = 1;
        CIAttributeDescription = "The intensity of the edges. The larger the value, the higher the intensity.";
        CIAttributeDisplayName = Intensity;
        CIAttributeIdentity = 0;
        CIAttributeMin = 0;
        CIAttributeSliderMax = 10;
        CIAttributeSliderMin = 0;
        CIAttributeType = CIAttributeTypeScalar;
    };

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

  • inputIntensity:强度,默认值1,范围0~10

实例

代码

    CIFilter *filter = [CIFilter filterWithName:@"CIEdges"];
    CIContext *context = [CIContext contextWithOptions:nil];
    NSLog(@"%@ - %@", filterName, filter.attributes);
    if (filter.attributes[kCIInputImageKey]) {
        [filter setValue:inputImage forKey:kCIInputImageKey];
        
        if (filter.attributes[kCIInputIntensityKey]) {
            [filter setValue:@(3) forKey:kCIInputIntensityKey];
        }


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

效果

CIEdges 滤镜的使用_第2张图片

你可能感兴趣的:(CIEdges 滤镜的使用)