滤镜链:即用一个滤镜的output image 当作 另一个滤镜的 input:
1 CIContext *context = [CIContext contextWithOptions:nil]; 2 CIImage *image = [CIImage imageWithCGImage:[UIImage imageNamed:@"aa11.jpg"].CGImage]; 3 4 5 6 CIFilter *filter = [CIFilter filterWithName:@"CISepiaTone"]; 7 [filter setValue:image forKey:kCIInputImageKey]; 8 [filter setValue:@0.8f forKey:kCIInputIntensityKey]; 9 CIImage *result = [filter valueForKey:kCIOutputImageKey]; 10 11 CIFilter *gloom = [CIFilter filterWithName:@"CIGloom"]; 12 [gloom setValue:result forKey:kCIInputImageKey]; 13 [gloom setValue:@15.0f forKey:kCIInputRadiusKey]; 14 [gloom setValue:@0.55f forKey:kCIInputIntensityKey]; 15 result = [gloom valueForKey:kCIOutputImageKey]; 16 17 CIFilter *bumpDistortion = [CIFilter filterWithName:@"CIBumpDistortion"]; 18 [bumpDistortion setValue:result forKey:kCIInputImageKey]; 19 [bumpDistortion setValue:[CIVector vectorWithX:300 Y:50] forKey:kCIInputCenterKey]; 20 [bumpDistortion setValue:@100.0f forKey:kCIInputRadiusKey]; 21 [bumpDistortion setValue:@3.0f forKey:kCIInputScaleKey]; 22 result = [bumpDistortion valueForKey:kCIOutputImageKey]; 23 24 25 CGRect extent = [result extent]; 26 CGImageRef cgImage = [context createCGImage:result fromRect:extent]; 27 28 UIImage *resultImg = [UIImage imageWithCGImage:cgImage]; 29 30 UIImageView *imgView = [[UIImageView alloc]initWithFrame:self.view.bounds]; 31 [imgView setImage:resultImg]; 32 [self.view addSubview:imgView];
时间: 2024-10-11 16:44:28