Take screenshot from camera view
Asked Answered
N

3

2

Updated

I'm using the sinch library to make video call in my app. I've button to take screenshot for the whole screen during the video call :

   @IBAction func photoAction(_ sender: Any) {

    let result = UIImage(view: self.videoView)
    UIImageWriteToSavedPhotosAlbum(result, nil, nil, nil)

    let result2 = UIImage(view: self.videoController!.localView())
    UIImageWriteToSavedPhotosAlbum(result2, nil, nil, nil)

}

call is SINClient
videoController is SINVideoController
localView is UIView, the camera view

The screenshot function work fine but the camera view is not appearing in the screenshot.

for example, this's screenshot self.view programmatically : enter image description here

and this screenshot how it should be : enter image description here

This problem's commun and I've seen many user having the same issue that they can't take screenshot for the camera view but no helpful answer was given.

Nonchalance answered 20/12, 2016 at 9:47 Comment(4)
can you not use standard "ios" functionality to capture a screen shot ?Jordain
which one ? how ?Nonchalance
I think this should help... https://mcmap.net/q/258036/-how-do-i-take-a-full-screen-screenshot-in-swift/3118477Daytime
I've already tried but doesn't help :/Nonchalance
N
0

To solve this issue, I'had to switch the video call camera from back to front camera so that user could user the back camera to take photo, once he done with taking photo I switch back the video call to back camera.

Nonchalance answered 19/5, 2017 at 7:44 Comment(0)
J
1

Well I usually use this code if I want to trigger a simple screenshot:

static func screenshotOf(window: UIWindow) -> UIImage? {

UIGraphicsBeginImageContextWithOptions(window.bounds.size, true, UIScreen.main.scale)

        guard let currentContext = UIGraphicsGetCurrentContext() else {
            return nil
        }

        window.layer.render(in: currentContext)
        guard let image = UIGraphicsGetImageFromCurrentImageContext() else {
            UIGraphicsEndImageContext()
            return nil
        }

        UIGraphicsEndImageContext()
        return image
    }

I guess that should work for your issue as well

Jordain answered 20/12, 2016 at 10:25 Comment(2)
The problem that my view is containing camera session subviews I think I should use AVFoundation to take screenshot I'm not sureNonchalance
I see what you mean, since you are triggering the screen shot from a button I thought that should help,anyway have you checked out this question ? #15864088Jordain
N
0

To solve this issue, I'had to switch the video call camera from back to front camera so that user could user the back camera to take photo, once he done with taking photo I switch back the video call to back camera.

Nonchalance answered 19/5, 2017 at 7:44 Comment(0)
D
0

Blank or Black Screen shot while camera is open or On in iOS Swift (Scandit)

Screen shot saves black image not including camera content

In my case I was taking screen shot while scanning the passport with scandit SDK and in result that was a blank (black) image see attached image in my case, Then I took image from scandit(SDK) image buffer and use that image as your screen shot.

There might be some camera SDK you will be using in your app which is preventing to take screen shot and in result return blank (black) image.

You have to take image from your (SDK) image buffer.

func idCapture(_ idCapture: IdCapture, didCaptureIn session: IdCaptureSession, frameData: FrameData) {

    let screenShot:UIImage = frameData.imageBuffers[0].image!
    UIImageWriteToSavedPhotosAlbum(screenShot, nil, nil, nil)
}

enter image description here

Dysphoria answered 29/5, 2023 at 9:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.