gpt4 book ai didi

ios - 使用 Swift 将相机焦点设置在点击点上

转载 作者:搜寻专家 更新时间:2023-10-30 22:02:55 49 4
gpt4 key购买 nike

用于在 swift 中使用相机的 API 似乎有所不同,我很难将相机聚焦在一个点上。当用户点击屏幕时,我希望相机聚焦在那个点上

这是我的代码:

 func focusCamera(point:CGPoint)
{
var screenRect:CGRect = bounds
var focusX = Float(point.x/screenRect.width)
var focusY = Float(point.y/screenRect.height)

_currentDevice.lockForConfiguration(nil)
_currentDevice.setFocusModeLockedWithLensPosition(focusX)
{
time in
self._currentDevice.unlockForConfiguration()
}

_currentDevice.setFocusModeLockedWithLensPosition(focusY)
{
time in
self._currentDevice.unlockForConfiguration()
}
}

但是好像不行。

我们非常欢迎任何建议!

最佳答案

@ryantxr 对 Swift 3 的更新回答:

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let screenSize = videoView.bounds.size
if let touchPoint = touches.first {
let x = touchPoint.location(in: videoView).y / screenSize.height
let y = 1.0 - touchPoint.location(in: videoView).x / screenSize.width
let focusPoint = CGPoint(x: x, y: y)

if let device = captureDevice {
do {
try device.lockForConfiguration()

device.focusPointOfInterest = focusPoint
//device.focusMode = .continuousAutoFocus
device.focusMode = .autoFocus
//device.focusMode = .locked
device.exposurePointOfInterest = focusPoint
device.exposureMode = AVCaptureExposureMode.continuousAutoExposure
device.unlockForConfiguration()
}
catch {
// just ignore
}
}
}
}

关于ios - 使用 Swift 将相机焦点设置在点击点上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26682450/

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