问题
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 SINClientvideoController
is SINVideoControllerlocalView
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