In Objective-C, how can we blur a face with a round / round shape?

I am working on an iOS application in which I detect a face from an image and face blur, I have already achieved a face blur in a rectangular shape, but for me it requires a face blur in a rounded shape. what i tried is

-(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;
    }
}

Using this method, I managed to blur the face with a rounded shape or a circular shape, but when I take a screenshot to save a blurry image in the application database, its Alpha will become 0, and the blur area will become visible, the code that I use to take screenshots

CGRect rect = viewShow.frame;
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[viewShow.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

here is the image before and after the screenshots after Applying Blur EffectsAfter taking Screen shot Alpha becomes 0

Now I have used this category and achieved this blur in a rectangular shape. Attached Image enter image description here

. 1- ? 2- Alpha 0, .

: enter image description here

.

+4

All Articles