这是所有图像的高斯滤波器
//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];
我正在搜索仅对图像中的触摸区域应用模糊滤镜但仅为整个图像创建此滤镜的clases。我的问题是如何使CIFilter仅适用于:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{ ... }
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{ ... }
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{ ... }
答案 0 :(得分:0)
这样的Juste应该有效:
- (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];
}
其他方法也一样:)