完成焦距变焦设定

This commit is contained in:
bluesea 2024-03-14 11:37:35 +08:00
parent e62f93f9a7
commit 975a4cdfb4

View File

@ -13,6 +13,7 @@ import VideoToolbox
import SVProgressHUD import SVProgressHUD
class CCSpatialShootController: BaseController { class CCSpatialShootController: BaseController {
var wideAngleCameraDevice:AVCaptureDevice?//使
//AVCaptureSession --- //AVCaptureSession ---
var session = AVCaptureMultiCamSession()// var session = AVCaptureMultiCamSession()//
@ -368,11 +369,13 @@ class CCSpatialShootController: BaseController {
print("Could not find the back camera") print("Could not find the back camera")
return return
} }
wideAngleCameraDevice = backCamera
do { do {
print("builtInWideAngleCamera:\(backCamera.videoZoomFactor)") print("builtInWideAngleCamera:\(backCamera.videoZoomFactor)")
// try backCamera.lockForConfiguration() // try backCamera.lockForConfiguration()
// backCamera.videoZoomFactor=3.0 // backCamera.videoZoomFactor=1.0
// backCamera.unlockForConfiguration() // backCamera.unlockForConfiguration()
wideAngleCameraDeviceInput = try AVCaptureDeviceInput(device: backCamera) wideAngleCameraDeviceInput = try AVCaptureDeviceInput(device: backCamera)
@ -396,9 +399,7 @@ class CCSpatialShootController: BaseController {
do { do {
print("builtInUltraWideCamera:\(frontCamera.videoZoomFactor)") print("builtInUltraWideCamera:\(frontCamera.videoZoomFactor)")
// try frontCamera.lockForConfiguration()
// frontCamera.videoZoomFactor = 8.0//
// frontCamera.unlockForConfiguration()
// //
// frontCamera.focusMode = .autoFocus // frontCamera.focusMode = .autoFocus
ultraWideCameraDeviceInput = try AVCaptureDeviceInput(device: frontCamera) ultraWideCameraDeviceInput = try AVCaptureDeviceInput(device: frontCamera)
@ -468,9 +469,14 @@ class CCSpatialShootController: BaseController {
// // view.layer.addSublayer(ultraWideCameraVideoPreviewLayer) // // view.layer.addSublayer(ultraWideCameraVideoPreviewLayer)
// self.view.layer.insertSublayer(ultraWideCameraVideoPreviewLayer, at: 0) // self.view.layer.insertSublayer(ultraWideCameraVideoPreviewLayer, at: 0)
// } // }
DispatchQueue.global().async { DispatchQueue.global().async {
self.session.startRunning() self.session.startRunning()
//AVCaptureMultiCamSession statrunning
try! frontCamera.lockForConfiguration()
frontCamera.videoZoomFactor = 1.75//
frontCamera.unlockForConfiguration()
} }
} }
@ -589,6 +595,20 @@ class CCSpatialShootController: BaseController {
// //
@objc func shutterPhotoButtonAction(){ @objc func shutterPhotoButtonAction(){
// do {
// try wideAngleCameraDevice?.lockForConfiguration()
//// wideAngleCameraDevice?.ramp(toVideoZoomFactor: wideAngleCameraDevice!.videoZoomFactor+1.0, withRate: 2)
// wideAngleCameraDevice?.videoZoomFactor = wideAngleCameraDevice!.videoZoomFactor+1.0
// wideAngleCameraDevice?.unlockForConfiguration()
//
// print("factor:\(wideAngleCameraDevice!.videoZoomFactor)")
// }
// catch {
// print("wide:err")
// }
//
// return
shutterPhotoButton.backgroundColor = .gray shutterPhotoButton.backgroundColor = .gray
imgs.removeAllObjects() imgs.removeAllObjects()