gpt4 book ai didi

ios - AVCaptureVideoPreviewLayer 从视频切换并以静态图像模式捕获图像时的延迟

转载 作者:行者123 更新时间:2023-11-30 11:00:32 27 4
gpt4 key购买 nike

我正在使用一个库,使用相机和视频在我的 swift 应用程序上创建自定义相机 https://github.com/yonat/CameraBackground

但是我遇到了延迟,当闪光灯设置关闭时,相机将使用闪光灯拍摄图像将相机模式从视频切换为静态图像时,我尝试在更改输出后拍摄图像

不幸的是,如果我不设置延迟,它将返回黑暗的图像。

代码:

@IBAction func startCapture(_ sender: Any) {
DispatchQueue.background(delay: 0.1, background: {
// do something in background
let currentSession = self.previewLiveCamera.cameraLayer?.session
currentSession!.sessionPreset = AVCaptureSession.Preset.photo
currentSession!.addOutput(AVCaptureStillImageOutput())


}, completion: {
// when background job finishes, wait 3 seconds and do something in main thread

self.previewLiveCamera.takeCameraSnapshot( {
// animate snapshot capture
print("Starting...")
},
completion: { (capturedImage, error) -> () in
if capturedImage != nil {
print("compleated with image")
RZTransitionsManager.shared().defaultPresentDismissAnimationController = RZZoomAlphaAnimationController()
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let nextViewController = storyboard.instantiateViewController(withIdentifier: "post") as! PostViewController
nextViewController.image = capturedImage
nextViewController.transitioningDelegate = RZTransitionsManager.shared()
self.present(nextViewController, animated: true, completion: {
self.previewLiveCamera.removeCameraBackground()
self.addvideoCamBackground()
self.hideCaptureBtns()
self.progressView.popIn()
self.progressView.transform = CGAffineTransform(rotationAngle: .pi)
})

}

})
})

}

最佳答案

CameraBackground 自述文件的用法:

view.addCameraBackground()
// ...
view.takeCameraSnapshot( {
// animate snapshot capture
self.view.alpha = 0
UIView.animate(withDuration: 1) { self.view.alpha = 1 }
}, completion: { (capturedImage, error) -> () in
self.view.freeCameraSnapshot() // unfreeze image
// ... handle capturedImage and error
})
// ...
view.removeCameraBackground()

你可以看到,在使用中使用这个间隔来设置可见性,所以如果你从代码中删除延迟,alpha 保持为 0。所以按照 GitHub 中描述的方式使用它与你的代码:

view.addCameraBackground()

view.takeCameraSnapshot( {
print("Starting...")
self.view.alpha = 0
UIView.animate(withDuration: 1) { self.view.alpha = 1 }
}, completion: { (capturedImage, error) -> () in
self.view.freeCameraSnapshot()
if capturedImage != nil {
print("compleated with image")
RZTransitionsManager.shared().defaultPresentDismissAnimationController = RZZoomAlphaAnimationController()
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let nextViewController = storyboard.instantiateViewController(withIdentifier: "post") as! PostViewController
nextViewController.image = capturedImage
nextViewController.transitioningDelegate = RZTransitionsManager.shared()
self.present(nextViewController, animated: true, completion: {
self.previewLiveCamera.removeCameraBackground()
self.addvideoCamBackground()
self.hideCaptureBtns()
self.progressView.popIn()
self.progressView.transform = CGAffineTransform(rotationAngle: .pi)
})

}
})

view.removeCameraBackground()

关于ios - AVCaptureVideoPreviewLayer 从视频切换并以静态图像模式捕获图像时的延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53429191/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com