1 year ago

#82634

test-img

user16563999

Blurring the image shown on screen when flipping camera - Swift

I am making a custom camera app with functionality to let you take photos with the front camera and the back camera. I have tried almost every code that I have found on internet but none of those have helped me transition from the back camera view to the front camera view (i.e. the preview before taking a photo) in a smooth way. I would like for this transition to be like instagram's camera. First, after pressing a button to change camera from front to back (and viceversa) the image freezes and blurs, then, after about half a second (maybe less) the other camera input is shown in the preview and the blurring effect disappears.

I have already tried using the UIEffect of blur but I can't avoid the screen turning black after I remove input from back camera and add input of the front camera (and viceversa).

Anything helps!

This is my actual function for when the flip camera button is pressed:

//Camera flip func
@IBAction func cameraFlipButtonPressed(_ sender: UIButton) {
    usingFrontCamera = !usingFrontCamera //Boolean (true if using front camera)
    
        do{
            session?.removeInput(session!.inputs.first!) //Removing the input of whichever camera
            
            if(usingFrontCamera){
                dev = getFrontCamera() //Func that returns AVCaptureDevice with media type: AVMediaType.video (of course) and position: .front
            }else{
                dev = getBackCamera() //Func that returns same thing but with position: .back
            }
            
            let captureDeviceInput1 = try AVCaptureDeviceInput(device: dev!) //dev declared as follows as global var -> var dev = AVCaptureDevice.default(for: .video)
            session!.addInput(captureDeviceInput1) //Adding the input
            
            
        }catch{
            print(error.localizedDescription)
        }

}

ios

swift

camera

uiblureffect

0 Answers

Your Answer

Accepted video resources