我正在开发 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();
这是屏幕截图之前和之后的图像
现在我已经使用了这个类别并以矩形形式实现了这个模糊图像已附加
现在我有两个问题。1-我怎样才能只模糊圆形或圆形的脸?2-当我以编程方式截取屏幕截图时,为什么 Alpha 变为 0。
所需的模糊看起来像这样
您的帮助将不胜感激。