使用 AVCaptureDevice 缩放设置

问题描述 投票:0回答:1

[在此处输入图像描述][1]我正在尝试为我的相机创建自动变焦。然而,我什至还没有接近弄清楚。 https://developer.apple.com/documentation/avfoundation/avcapturedevice/1624614-ramp 我一直在尝试使用此斜坡函数,但每次尝试调用该函数时都会出现错误。 我只是希望变焦在 5 秒的时间间隔内从一路“缩小”到一路“放大”。请帮助我了解我需要做什么才能创建该功能。

func autoZoom() {
  let camera = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo)
  do { 
    try camera?.lockForConfiguration()
    camera?.videoZoomFactor = 5
    camera?.ramp(toVideoZoomFactor: 1, withRate: 0.4)
  } catch { }
}
zooming avcapturedevice
1个回答
0
投票

渐变设置得很快,请尝试设置延迟或使用某种用户交互来渐变到新的缩放级别。这是一个证明我的理论的例子。

camera?.videoZoomFactor = 5
DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: {
    camera?.ramp(toVideoZoomFactor: 1, withRate: 0.4)
})
© www.soinside.com 2019 - 2024. All rights reserved.