简体   繁体   中英

How to find the CIFIlter categories at runtime?

I'm using this [CIFilter filterNamesInCategories:nil] to get the list of available filters, but how can I get the list of categories ? I could certainly enumerate through the filters list, and read the categories in each filter to build a set, but is there a better way to do this ?

Here is how I did it:

NSMutableSet  * categories = [NSMutableSet set];
for (NSString* filterName in [CIFilter filterNamesInCategories:nil])
{
    for (id value in  [[[CIFilter filterWithName:filterName] attributes] 
    valueForKey:@"CIAttributeFilterCategories"]) {
        [categories addObject:value];
    }
}
NSLog(@"%@", categories);

Swift 4.2 version is here.

  import CoreImage

  var results = NSMutableSet()
  let categories = CIFilter.filterNames(inCategory: nil)

  for category in categories {
      let attributes = CIFilter(name: category)?.attributes
      let filterCategories = attributes!["CIAttributeFilterCategories"]
      results.addObjects(from: filterCategories as! [Any])
  }

  print(results)

This is from the documentation:

Filter Category Keys

Categories of filters.

extern NSString *kCICategoryDistortionEffect;
extern NSString *kCICategoryGeometryAdjustment;
extern NSString *kCICategoryCompositeOperation;
extern NSString *kCICategoryHalftoneEffect;
extern NSString *kCICategoryColorAdjustment;
extern NSString *kCICategoryColorEffect;
extern NSString *kCICategoryTransition;
extern NSString *kCICategoryTileEffect;
extern NSString *kCICategoryGenerator;
extern NSString *kCICategoryReduction;
extern NSString *kCICategoryGradient;
extern NSString *kCICategoryStylize;
extern NSString *kCICategorySharpen;
extern NSString *kCICategoryBlur;
extern NSString *kCICategoryVideo;
extern NSString *kCICategoryStillImage;
extern NSString *kCICategoryInterlaced;
extern NSString *kCICategoryNonSquarePixels;
extern NSString *kCICategoryHighDynamicRange ;
extern NSString *kCICategoryBuiltIn;

As for getting them in runtime, I don't see any other option, other than enumerating them. Here is the answer to that

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM