How to get the list of filter names in CIFilter class?

后端 未结 7 1770
感情败类
感情败类 2021-01-30 23:40

I am using the following code for exposure adjustment and its working. I need the filter names for sharpen, denoise, highlighs, color temperature, shadows, blur, etc.

         


        
相关标签:
7条回答
  • 2021-01-30 23:55

    May be you can try following method of CIFilter class

    + (NSArray *)filterNamesInCategory:(NSString *)category
    
    0 讨论(0)
  • 2021-01-30 23:59

    All you need to do is ask CIFilter for the filter names. You can then ask each filter for its attributes, which returns a dictionary that describes each input and output parameter that the filter accepts.

    NSArray* filters = [CIFilter filterNamesInCategories:nil];
    for (NSString* filterName in filters)
    {
        NSLog(@"Filter: %@", filterName);
        NSLog(@"Parameters: %@", [[CIFilter filterWithName:filterName] attributes]);
    }
    

    For example, this is the output of the above code for the CIZoomBlur filter:

    Filter: CIZoomBlur
    Parameters: {
        CIAttributeDescription = "Simulates the effect of zooming the camera while capturing the image.";
        CIAttributeFilterCategories =     (
            CICategoryBlur,
            CICategoryVideo,
            CICategoryStillImage,
            CICategoryBuiltIn
        );
        CIAttributeFilterDisplayName = "Zoom Blur";
        CIAttributeFilterName = CIZoomBlur;
        CIAttributeReferenceDocumentation = "http://developer.apple.com/cgi-bin/apple_ref.cgi?apple_ref=//apple_ref/doc/filter/ci/CIZoomBlur";
        inputAmount =     {
            CIAttributeClass = NSNumber;
            CIAttributeDefault = 20;
            CIAttributeDescription = "The zoom-in amount. Larger values result in more zooming in.";
            CIAttributeDisplayName = Amount;
            CIAttributeIdentity = 0;
            CIAttributeMin = 0;
            CIAttributeSliderMax = 200;
            CIAttributeSliderMin = 0;
            CIAttributeType = CIAttributeTypeDistance;
            CIUIParameterSet = CIUISetBasic;
        };
        inputCenter =     {
            CIAttributeClass = CIVector;
            CIAttributeDefault = "[150 150]";
            CIAttributeDescription = "The x and y position to use as the center of the effect.";
            CIAttributeDisplayName = Center;
            CIAttributeType = CIAttributeTypePosition;
            CIUIParameterSet = CIUISetBasic;
        };
        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;
            CIUIParameterSet = CIUISetBasic;
        };
        outputImage =     {
            CIAttributeClass = CIImage;
        };
    }
    

    Most of the time, though, you'll probably just use the docs.

    0 讨论(0)
  • 2021-01-31 00:00

    iOS 14, Swift 5

    Must confess not easy to read, but an answer that is comparable to the first one on Objective C.

    for filtername in filters {
      print("filter \(filtername)")
      print("attributes \(CIFilter.init(name: filtername)?.attributes.keys.description)")
    }
    

    Produces this ...

    filter CIAccordionFoldTransition
    attributes Optional("[\"inputImage\", \"CIAttributeFilterDisplayName\",     \"inputTargetImage\", \"CIAttributeFilterAvailable_iOS\", \"CIAttributeFilterAvailable_Mac\", \"inputNumberOfFolds\", \"inputFoldShadowAmount\", \"inputBottomHeight\", \"CIAttributeReferenceDocumentation\", \"inputTime\", \"CIAttributeFilterCategories\", \"CIAttributeFilterName\"]")
    filter CIAdditionCompositing
    attributes Optional("[\"CIAttributeFilterCategories\", \"CIAttributeFilterName\", \"CIAttributeFilterDisplayName\", \"inputImage\", \"CIAttributeReferenceDocumentation\", \"CIAttributeFilterAvailable_iOS\", \"CIAttributeFilterAvailable_Mac\", \"inputBackgroundImage\"]")
    

    So the info is there in these long strings, you just need to pick it out :)

    0 讨论(0)
  • 2021-01-31 00:01

    I was writing to your earlier post link to all filters. I will repeat: link to all filters.

    And for example You need Blur effect. Blur is category and have 7 filters:

    • CIBoxBlur
    • CIDiscBlur
    • CIGaussianBlur
    • CIMedianFilter
    • CIMotionBlur
    • CINoiseReduction
    • CIZoomBlur.

    And etc..

    0 讨论(0)
  • 2021-01-31 00:02
    NSLog(@"Distortion: %@", [CIFilter filterNamesInCategory:kCICategoryDistortionEffect]);
    NSLog(@"Blurs: %@", [CIFilter filterNamesInCategory:kCICategoryBlur]);
    NSLog(@"Color effects: %@", [CIFilter filterNamesInCategory:kCICategoryColorEffect]);
    NSLog(@"Color adjustment: %@", [CIFilter filterNamesInCategory:kCICategoryColorAdjustment]);
    NSLog(@"Built-in effects: %@", [CIFilter filterNamesInCategory:kCICategoryBuiltIn]);
    
    0 讨论(0)
  • 2021-01-31 00:05

    In Swift (4.2, at the time of writing this), you can use this code to get all filter names:

    For filters in a specified category:

    CIFilter.filterNames(inCategory: "Name_of_the_category")
    

    For filters in specified categories:

    CIFilter.filterNames(inCategories: ["Name_of_the_category_1", "Name_of_the_category_2"])
    

    For filters in all categories, just pass nil either in inCategory or inCategories:

    CIFilter.filterNames(inCategory: nil)
    

    or

    CIFilter.filterNames(inCategories: nil)
    

    All the functions above returns an Array of the filter names in String values:

    [ "CIAccordionFoldTransition", "CIAdditionCompositing", "CIAffineClamp", "CIAffineTile", "CIAffineTransform", "CIAreaAverage", "CIAreaHistogram"... ]

    0 讨论(0)
提交回复
热议问题