是的,似乎一些过滤器尚未适用于iOS。阅读文档时我也有同样的经历。但您可以通过代码检查iOS可用的过滤器,就像上面的说话者所说的那样。例如,文档中没有发现的CIVingette等某些过滤器,我这样做也是为了获取5.1上每个可用过滤器的值参数。
NSArray *supportedFilters = [CIFilter filterNamesInCategory:kCICategoryBuiltIn];
for (CIFilter *filter in supportedFilters) {
NSString *string = [NSString stringWithFormat:@"%@",[[CIFilter filterWithName:(NSString *)filter] inputKeys]];
NSLog(@"%@ %@", filter, string);
}
响应:
...
2012-04-19 14:02:55.597 ImageFiltering[12190:707] CIVibrance (
inputImage,
inputAmount
)
2012-04-19 14:02:55.599 ImageFiltering[12190:707] CIVignette (
inputImage,
inputIntensity,
inputRadius
)
2012-04-19 14:02:55.601 ImageFiltering[12190:707] CIWhitePointAdjust (
inputImage,
inputColor
)
...
请注意,将来(或者已经有人知道在哪里可以找到更多信息),您可能希望阅读文档。这只是我玩侦探绕过它的方法,因为我没有找到任何关于一些过滤器的文档,就像我之前提到的那样。
这是我从以前的信息中得到的CIVingette的示例:
- (void)displayVingetteFilterWithImage{
// 获取图像并将其设置为CIImage
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"image_1" ofType:@"jpg"];
NSURL *fileNameAndPath = [NSURL fileURLWithPath:filePath];
CIImage *image = [CIImage imageWithContentsOfURL:fileNameAndPath];
// 创建上下文
CIContext *imageContext = [CIContext contextWithOptions:nil];
// 将过滤器设置为图像,在这种情况下为CIVignette,知道它使用先前的日志响应中的inputImage、inputIntensity和inputRadius。
CIFilter *vignette = [CIFilter filterWithName:@"CIVignette"];
[vignette setDefaults];
[vignette setValue: image forKey: @"inputImage"];
[vignette setValue: [NSNumber numberWithFloat: 5.0] forKey: @"inputIntensity"];
[vignette setValue: [NSNumber numberWithFloat: 30.0] forKey: @"inputRadius"];
// 将CIImage附加到CGImageRef并将其作为UIImage附加
CIImage *result = [vignette valueForKey: @"outputImage"];
CGImageRef cgImageRef = [imageContext createCGImage:result fromRect:[result extent]];
UIImage *targetImage = [UIImage imageWithCGImage:cgImageRef];
// 将UIImage附加到self.view中的UIImageView,也将其定位,只是为了好玩。
UIImageView *imageView = [[UIImageView alloc] initWithImage:targetImage];
[self.view addSubview:imageView];
[imageView setImage:targetImage];
imageView.frame = CGRectMake(0.0, 10.0, imageView.frame.size.width, imageView.frame.size.height);
// 释放我们之前创建的CGImageRef。
CGImageRelease(cgImageRef);
}