1

CIColorPosterize 在 iOS 中可用吗?我将以下代码用于核心图像过滤器,但过滤器值始终为 0。棕褐色过滤器工作正常。我只是想知道 CIColorPosterize 在 iOS 中是否可用,如果是,我的代码中的问题是什么。感谢您的帮助。

-(void)imageDraw{

UIImage *image = [UIImage imageNamed:@"cat2.jpg"];

CIImage *beginImage = [CIImage imageWithCGImage:[image CGImage]];
CIContext *context = [CIContext contextWithOptions:nil];
 CIFilter* posterize = [CIFilter filterWithName:@"CIColorPosterize"];
[posterize setDefaults];
[posterize setValue:[NSNumber numberWithDouble:8.0] forKey:@"inputLevels"];
[posterize setValue:beginImage forKey:@"inputImage"];


CIImage *outputImage = [posterize outputImage];

CGImageRef cgimg = [context createCGImage:outputImage fromRect:[outputImage extent]];
UIImage *newImg = [UIImage imageWithCGImage:cgimg];


imgVIew.image = newImg;
 ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];  

[library writeImageToSavedPhotosAlbum:[newImg CGImage] orientation:(ALAssetOrientation)           [newImg imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){  
    if (error) {  
        NSLog(@"error");  
    } else {  
        NSLog(@"url %@", assetURL);  
    }  
}];  

CGImageRelease(cgimg);
}
4

2 回答 2

0

这个页面上,他们列出了所有的CIFilters,他们列出了每个版本的 MacOS 和 iOS 可用,并且CIColorPosterize没有列出在 iOS 上可用。您也可以尝试[+CIFilter filterNamesInCategory:]使用该类别进行呼叫,CICategoryColorEffect看看您是否回到CIColorPosterize列表中。

于 2012-07-13T04:32:34.517 回答
0

更新

CIColorPosterize 现在可用于 iOS 6

-(void)logAllFilters {
    NSArray *properties = [CIFilter filterNamesInCategory:
      kCICategoryBuiltIn];
    NSLog(@"%@", properties);
    for (NSString *filterName in properties) {
        CIFilter *fltr = [CIFilter filterWithName:filterName];
        NSLog(@"%@", [fltr attributes]);
    }
}
于 2012-07-13T04:34:17.723 回答