微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

高斯模糊滤镜逆转:iOS

我有一个高斯模糊,我正在为一个应用程序做.

//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
    newView = [[UIImageView alloc] initWithFrame:self.view.bounds];
    newView.image = endImage;
    [self.view addSubview:newView];

它工作得很好,但我希望能够将其反转并使视图恢复正常.

我怎么能这样做,因为试图简单地从它的超视图中移除模糊的视图不起作用.我也尝试过将各种属性设置为零而没有运气.

解决方法

属性中保留指向viewImage的指针

@property (nonatomic,strong) UIImage* originalImage;

然后

UIImage *viewImage = UIGraphicsGetimageFromCurrentimageContext();

self.originalImage = viewImage;

要还原您的图像:

newView.image = self.originalImage;

当你应用模糊时它不会改变viewImage ..你创建了一个单独的CIImage,它变得模糊,你从模糊的CIImage中创建一个新的UIImage.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐