高斯模糊滤镜逆转: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.

相关文章

在有效期内的苹果开发者账号(类型为个人或者公司账号)。还...
Appuploader官网--IOS ipa上传发布工具,证书制作工具跨平台...
苹果在9月13号凌晨(北京时间)发布 iOS 16,该系统的设备可...
计算机图形学--OpenGL递归实现光线追踪
Xcode 14打出来的包在低版本系统运行时会崩溃,报错信息是Li...