我使用波纹管代码进行图像模糊。 'resultImage'显示模糊图像,但是当我把它放在CALayer内容上时它什么也没显示。
CIImage *imageToBlur = [CIImage imageWithCGImage:image.CGImage];
CIFilter *gaussianBlurFilter = [CIFilter filterWithName: @"CIGaussianBlur"];
[gaussianBlurFilter setValue:imageToBlur forKey: @"inputImage"];
[gaussianBlurFilter setValue:[NSNumber numberWithFloat: 10] forKey: @"inputRadius"];
CIImage *resultImage = [gaussianBlurFilter valueForKey: @"outputImage"];
self.contents = resultImage;
答案 0 :(得分:3)
您无法使用CIImage
作为CALayer
的内容。可能存在一些VRM问题。我不再赘述了。顺便说一句,您可以使用CGImageRef
代替CIImage
。根据你的代码,你可以做的事情......
CIImage *imageToBlur = [CIImage imageWithCGImage:image.CGImage];
CIFilter *gaussianBlurFilter = [CIFilter filterWithName: @"CIGaussianBlur"];
[gaussianBlurFilter setValue:imageToBlur forKey: @"inputImage"];
[gaussianBlurFilter setValue:[NSNumber numberWithFloat: 10] forKey: @"inputRadius"];
CIImage *resultImage = [gaussianBlurFilter valueForKey: @"outputImage"];
CIContext *cont = [CIContext contextWithOptions:nil];
CGImageRef img = [cont createCGImage:resultImage fromRect:CGRectMake(0, 0, image.size.width, image.size.height)];
self.contents = (__bridge id)img;
我希望它能奏效!