Take screenshot from camera view

廉价感情. 提交于 2020-01-21 22:57:44

问题


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 :

and this screenshot how it should be :

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.


回答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




回答2:


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.



来源:https://stackoverflow.com/questions/41239254/take-screenshot-from-camera-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!