2017-03-03 97 views
3

我使用圖像模糊的波紋管代碼。 'resultImage'顯示模糊的圖像,但是當我將它放在CALayer內容上時,它什麼也沒有顯示。作爲CALayer模糊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"]; 
self.contents = resultImage; 

回答

2

您cantn't使用CIImageCALayer內容。可能有一些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; 

我希望它能工作!