Iphone 如何在swift中为相机添加圆形遮罩

Iphone 如何在swift中为相机添加圆形遮罩,iphone,swift,camera,mask,Iphone,Swift,Camera,Mask,现在我是swift新手,但我想学习如何在swift中的相机上添加圆形面具。 现在我使用的是Xcode7.2.1和swift 2.1,但我对此一无所知。 我正在使用as第三方库开发这个摄像头应用程序。 在这里,我想在相机上添加我的自定义圆形遮罩。 我想知道谁能帮我得到这个! 感谢UIImagePickerController具有一个cameraOverlayView属性,您可以使用该属性提供一个自定义视图,该视图将用作覆盖。下面的示例创建了一个正方形的覆盖视图。试着用它来得到你想要的 @IBAct

现在我是swift新手,但我想学习如何在swift中的相机上添加圆形面具。 现在我使用的是Xcode7.2.1和swift 2.1,但我对此一无所知。 我正在使用as第三方库开发这个摄像头应用程序。 在这里,我想在相机上添加我的自定义圆形遮罩。 我想知道谁能帮我得到这个!
感谢

UIImagePickerController
具有一个
cameraOverlayView
属性,您可以使用该属性提供一个自定义视图,该视图将用作覆盖。下面的示例创建了一个正方形的覆盖视图。试着用它来得到你想要的

@IBAction func takePhoto(sender: AnyObject) {

    if !UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera){
        return
    }

    var imagePicker = UIImagePickerController()
    imagePicker.delegate = self
    imagePicker.sourceType = UIImagePickerControllerSourceType.Camera;

    //Create camera overlay
    let pickerFrame = CGRectMake(0, UIApplication.sharedApplication().statusBarFrame.size.height, imagePicker.view.bounds.width, imagePicker.view.bounds.height - imagePicker.navigationBar.bounds.size.height - imagePicker.toolbar.bounds.size.height)
    let squareFrame = CGRectMake(pickerFrame.width/2 - 200/2, pickerFrame.height/2 - 200/2, 200, 200)
    UIGraphicsBeginImageContext(pickerFrame.size)

    let context = UIGraphicsGetCurrentContext()
    CGContextSaveGState(context)
    CGContextAddRect(context, CGContextGetClipBoundingBox(context))
    CGContextMoveToPoint(context, squareFrame.origin.x, squareFrame.origin.y)
    CGContextAddLineToPoint(context, squareFrame.origin.x + squareFrame.width, squareFrame.origin.y)
    CGContextAddLineToPoint(context, squareFrame.origin.x + squareFrame.width, squareFrame.origin.y + squareFrame.size.height)
    CGContextAddLineToPoint(context, squareFrame.origin.x, squareFrame.origin.y + squareFrame.size.height)
    CGContextAddLineToPoint(context, squareFrame.origin.x, squareFrame.origin.y)
    CGContextEOClip(context)
    CGContextMoveToPoint(context, pickerFrame.origin.x, pickerFrame.origin.y)
    CGContextSetRGBFillColor(context, 0, 0, 0, 1)
    CGContextFillRect(context, pickerFrame)
    CGContextRestoreGState(context)

    let overlayImage = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext();

    let overlayView = UIImageView(frame: pickerFrame)
    overlayView.image = overlayImage
    imagePicker.cameraOverlayView = overlayView
    self.presentViewController(imagePicker, animated: true, completion: nil)

}

非常感谢。但是,你有在CameraManager工作过吗?如果有,我很高兴知道如何在swift 2.0中在相机中心添加定制的圆形遮罩。再次感谢。如何在“完成图像选取”代表中获取图像。我无法使用“信息[UIImagePickerControllerEditedImage]作为?UIImage”获取