如何在运行时找到CIFIlter类别?

时间:2013-04-04 08:11:56

标签: ios core-graphics

我正在使用此[CIFilter filterNamesInCategories:nil]获取可用过滤器列表,但如何获取类别列表?我当然可以通过过滤器列表进行枚举,并读取每个过滤器中的类别来构建一个集合,但是有更好的方法吗?

3 个答案:

答案 0 :(得分:1)

我是这样做的:

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);

答案 1 :(得分:1)

Swift 4.2版本在这里。

  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)

答案 2 :(得分:0)

这是from the documentation:

  

过滤类别键

     

过滤器类别。

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;

至于在运行时获取它们,除了枚举它们之外,我没有看到任何其他选项。 Here is the answer to that