我试图拍摄本地发布者视图的快照而未将发布者视图呈现为图像!
我搜索了很多示例,但对我无济于事,例如:Can't get screenshot of only the UIView which shows camera (AVCapturePhotoOutput) in Swift
Is it possible to take a snapshot of combined views including the camera?
我尝试了此代码,但无法正常工作,图片始终为零:
stillImageOutput.outputSettings = [AVVideoCodecKey:AVVideoCodecType.jpeg]
if localView.captureSession.canAddOutput(stillImageOutput) {
localView.captureSession.addOutput(stillImageOutput)
}
if let videoConnection = stillImageOutput.connection(with: AVMediaType.video) {
stillImageOutput.captureStillImageAsynchronously(from: videoConnection) {
(imageDataSampleBuffer, error) -> Void in
guard let imageDataBuffer = imageDataSampleBuffer else { return }
let imageData = UIImage.from(sampleBuffer: imageDataBuffer)
print("captured")
}
}
有人可以解决吗?谢谢