我在iOS应用程序中工作,我从图像和模糊的脸检测脸部,我已经实现了矩形的模糊面,但我需要的是模糊圆形的脸。我试过的是
-(void)markAfterFaceDetect:(NSArray *)features
{
for (CIFaceFeature *f in features)
{
CGRect aRect = f.bounds;
NSLog(@"here is the height of h %f",aRect.size.height);
// aRect.size.height=aRect.size.height+10;
aRect.origin.y = self.viewShow.bounds.size.height - aRect.size.height - aRect.origin.y;
NSLog(@"Height Of the Image Is : == %f",_imageView.image.size.height);
//self.bounds.size
rectFaceDetect = aRect;
UIVisualEffect *blurEffect;
blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *visualEffectView;
visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
visualEffectView.frame = vv.frame;
//visualEffectView.layer.cornerRadius = visualEffectView.frame.size.height/2;
visualEffectView.alpha =0.96;
visualEffectView.tag = markViewTag;
// [self.imageView addSubview:visualEffectView];
CAShapeLayer *mask = [CAShapeLayer layer];
mask.path = [UIBezierPath bezierPathWithOvalInRect:visualEffectView.bounds].CGPath;
visualEffectView.layer.mask = mask;
}
}
使用这种方式我已经设法模糊圆形或圆形的脸,但是当我拍摄视图的屏幕截图以保存应用程序数据库中的模糊图像时,其Alpha变为0并且模糊区域变得可见,我正在使用的代码截屏是
CGRect rect = viewShow.frame;
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[viewShow.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
这是截图前后的图像
Now i have used this Category and Achieved this Blur in Rectangular form Image is Attached
现在我有两个问题。 1-如何仅将脸部模糊成圆形或圆形? 2-当我以编程方式截取屏幕时,为什么Alpha变为0。
所需的模糊将如下所示
我们将非常感谢您的帮助。