Take screenshot from camera view

后端 未结 2 953
我寻月下人不归
我寻月下人不归 2021-01-25 06:52

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 :

2条回答
  •  半阙折子戏
    2021-01-25 07:15

    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

提交回复
热议问题