4

I am working on iOS app in which i detect face from Image and blurring face , i have already achieved blurring face in rectangular form but what i am required is to Blur face in rounded shape . what i have tried so for 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 way i have managed to blur face in rounded shape or circular shape but when i take screen shot of the view to save blurred image in application data base its Alpha become 0 and Blurred area becomes visible ,code whichi i am using for taking screenshot is

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

here are the Image before and after screenshots after Applying Blur Effects After taking Screen shot Alpha becomes 0

Now i have used this Category and Achieved this Blur in Rectangular form Image is Attached enter image description here

Now I have Two Questions . 1- How can i blur only face in rounded or circular shape? 2- Why Alpha becomes 0 when i took screenshot programatically .

Desired blur will look like this enter image description here

Your help will be highly appreciated .

Hayley Guillou
  • 3,953
  • 4
  • 24
  • 34
AHSAN NAZIR RAJA
  • 166
  • 1
  • 13

1 Answers1

1

Use drawViewHierarchyInRect:afterScreenUpdates: to capture the on-screen appearance of your view hierarchy.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848