仅在 xCode 中的触摸区域应用高斯模糊滤镜
Posted
技术标签:
【中文标题】仅在 xCode 中的触摸区域应用高斯模糊滤镜【英文标题】:Apply Gaussian Blur Filter only in Touched areas in xCode 【发布时间】:2014-09-12 08:05:46 【问题描述】:这里是所有图像的高斯滤波器
//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];
我正在寻找仅对图像中的触摸区域应用模糊过滤器但只为整个图像创建此过滤器的类。我的问题是关于如何使 CIFilter 仅适用于:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
...
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
...
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
...
【问题讨论】:
也许你可以用那些方法写代码? 好吧,如果我问这是否可能。还不知道该写什么。 【参考方案1】:像这样它应该可以工作:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
//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];
其他方法也一样:)
【讨论】:
不,这里你只是将整个图像模糊添加到默认图像。 哦,是的,抱歉,您想检测按下的区域并将模糊应用到该区域? 是的,这就是我要找的。类似于 Photoshop 的模糊工具。 我猜这应该对你有所帮助:***.com/questions/12558993/…以上是关于仅在 xCode 中的触摸区域应用高斯模糊滤镜的主要内容,如果未能解决你的问题,请参考以下文章
❤️Android 12 高斯模糊-RenderEffect❤️