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