Ios 在目标C中,如何模糊圆形/圆形的人脸?
我正在使用iOS应用程序,在这个应用程序中,我可以从图像中检测人脸和模糊人脸,我已经实现了矩形的模糊人脸,但我需要的是将人脸模糊为圆形。我这么做的目的是Ios 在目标C中,如何模糊圆形/圆形的人脸?,ios,objective-c,face-detection,uiblureffect,Ios,Objective C,Face Detection,Uiblureffect,我正在使用iOS应用程序,在这个应用程序中,我可以从图像中检测人脸和模糊人脸,我已经实现了矩形的模糊人脸,但我需要的是将人脸模糊为圆形。我这么做的目的是 -(void)markAfterFaceDetect:(NSArray *)features { for (CIFaceFeature *f in features) { CGRect aRect = f.bounds; NSLog(@"here is the height of h %f"
-(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();
以下是截图前后的图像
现在我有两个问题。
1-如何仅模糊圆形或圆形的面?
2-为什么当我按程序截图时Alpha变成0
所需的模糊将如下所示
我们将非常感谢你的帮助 用于捕获视图层次结构的屏幕外观