【问题标题】:Apply Gaussian Blur Filter only in Touched areas in xCode仅在 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
{ ... }

【问题讨论】:

  • 也许你可以用那些方法写代码?
  • 好吧,如果我问这是否可能。还不知道该写什么。

标签: ios xcode5


【解决方案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 的模糊工具。
  • 我猜这应该对你有所帮助:stackoverflow.com/questions/12558993/…
猜你喜欢
  • 2015-11-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-01
  • 2014-06-03
  • 2013-10-21
  • 2018-01-19
相关资源
最近更新 更多