CIGaussianBlur问题

时间:2014-05-06 22:36:23

标签: ios objective-c uiimageview

经过大量研究后,我发现了如何让iOS的CIGaussianBlur进行半工作。我试图模糊UIImageView,但它模糊了整个视图。这是我的代码:

// Get a UIImage from the UIView
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

// Blur the UIImage
CIImage *imageToBlur = [CIImage imageWithCGImage:viewImage.CGImage];
CIFilter *gaussianBlurFilter = [CIFilter filterWithName:@"CIGaussianBlur"];
[gaussianBlurFilter setValue:imageToBlur forKey:@"inputImage"];
[gaussianBlurFilter setValue:[NSNumber numberWithFloat:2] forKey:@"inputRadius"];
CIImage *resultImage = [gaussianBlurFilter valueForKey:@"outputImage"];
UIImage *endImage = [[UIImage alloc] initWithCIImage:resultImage];

// Place the UIImage in a UIImageView
_backgroundImage = [[UIImageView alloc] initWithFrame:self.view.bounds];
_backgroundImage.image = endImage;
[self.view addSubview:_backgroundImage];

(我的UIImageView的名字是backgroundImage)

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

您是否尝试创建iOS 7模糊?如果是这样,你可以使用这个类别......

https://github.com/iGriever/TWSReleaseNotesView/tree/master/TWSReleaseNotesView

这是苹果员工发布的一款,可以轻松重现iOS 7模糊。

只需拍摄快照,然后使用类别“applyLightEffects”等...