gpt4 book ai didi

swift - 在 Swift 4 中访问前置摄像头

转载 作者:搜寻专家 更新时间:2023-11-01 05:52:09 24 4
gpt4 key购买 nike

我的相机应用程序中有这个

session.sessionPreset = AVCaptureSession.Preset.high
camera = AVCaptureDevice.default(for: AVMediaType.video)

do {
let cameraCaptureInput = try AVCaptureDeviceInput(device: camera!)
cameraCaptureOutput = AVCapturePhotoOutput()

session.addInput(cameraCaptureInput)
session.addOutput(cameraCaptureOutput!)

} catch {
print(error.localizedDescription)
}

如何使用前置摄像头?

最佳答案

您可以这样设置您的AVCaptureDevice。只需将您的默认位置设置为前置摄像头。

        var defaultVideoDevice: AVCaptureDevice?

// Choose the back dual camera if available, otherwise default to a wide angle camera.
if let dualCameraDevice = AVCaptureDevice.default(.builtInDualCamera, for: AVMediaType.video, position: .back) {
defaultVideoDevice = dualCameraDevice
}

else if let backCameraDevice = AVCaptureDevice.default(.builtInWideAngleCamera, for: AVMediaType.video, position: .back) {
defaultVideoDevice = backCameraDevice
}

else if let frontCameraDevice = AVCaptureDevice.default(.builtInWideAngleCamera, for: AVMediaType.video, position: .front) {
defaultVideoDevice = frontCameraDevice
}

let videoDeviceInput = try AVCaptureDeviceInput(device: defaultVideoDevice!)

关于swift - 在 Swift 4 中访问前置摄像头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46922902/

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