【问题标题】:CIGaussianBlur issuesCIGaussianBlur 问题
【发布时间】:2014-05-07 06:41:10
【问题描述】:

经过大量研究,我发现了如何让 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)

感谢您的帮助!

【问题讨论】:

    标签: ios objective-c uiimageview


    【解决方案1】:

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

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

    这是一位苹果员工发布的,用于轻松重现 iOS 7 模糊。

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

    【讨论】:

      猜你喜欢
      • 2013-12-30
      • 2012-10-02
      • 2012-10-06
      • 2017-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多