abdullahselek / TakeASelfie

An iOS framework that uses the front camera, detects your face and takes a selfie.
MIT License
37 stars 6 forks source link

Added custom camera button #3

Closed KOSURUUDAYSAIKUMAR closed 3 years ago

KOSURUUDAYSAIKUMAR commented 4 years ago

IMG_1721 Sometimes within seconds a selfie is capturing & sometimes taking 10 to 12 seconds time. So I have added custom camera button to capture the image. Can you please let me know how to capture image on button click.

abdullahselek commented 4 years ago

Hi @KOSURUUDAYSAIKUMAR you can find below code block that saves the image when TakeASelfie detects a face inside green oval overlay. I think you can modify and use it.

fileprivate func handleFaceFeatures(features: [CIFeature],
                                        faceImage: CIImage,
                                        faceUIImage: UIImage) {
        guard let features = features as? [CIFaceFeature] else {
            return
        }
        if features.isEmpty || features.count > 2 {
            return
        }
        let image = UIImage(ciImage: faceImage)
        let faceFeature = features[0]
        let bounds = faceFeature.bounds(for: image, inView: ovalOverlayView.overlayFrame.size)
        if ovalOverlayView.overlayFrame.contains(bounds) {
            print("TakeASelfie: Face inside the overlay!")
            captureSession.stopRunning()
            UIImageWriteToSavedPhotosAlbum(faceUIImage,
                                           self,
                                           #selector(image(_:didFinishSavingWithError:contextInfo:)), nil)
        }
    }
KOSURUUDAYSAIKUMAR commented 4 years ago

hi @abdullahselek . Thank you for your quick response. Will check and let you know.

abdullahselek commented 3 years ago

Closing because of inactivity.