完成焦距变焦设定
This commit is contained in:
parent
e62f93f9a7
commit
975a4cdfb4
@ -13,6 +13,7 @@ import VideoToolbox
|
||||
import SVProgressHUD
|
||||
|
||||
class CCSpatialShootController: BaseController {
|
||||
var wideAngleCameraDevice:AVCaptureDevice?//测试使用
|
||||
|
||||
//AVCaptureSession --- 单摄像头
|
||||
var session = AVCaptureMultiCamSession()//多摄像头
|
||||
@ -368,11 +369,13 @@ class CCSpatialShootController: BaseController {
|
||||
print("Could not find the back camera")
|
||||
return
|
||||
}
|
||||
wideAngleCameraDevice = backCamera
|
||||
|
||||
do {
|
||||
print("builtInWideAngleCamera:\(backCamera.videoZoomFactor)")
|
||||
// try backCamera.lockForConfiguration()
|
||||
// backCamera.videoZoomFactor=3.0
|
||||
// backCamera.videoZoomFactor=1.0
|
||||
|
||||
// backCamera.unlockForConfiguration()
|
||||
|
||||
wideAngleCameraDeviceInput = try AVCaptureDeviceInput(device: backCamera)
|
||||
@ -396,9 +399,7 @@ class CCSpatialShootController: BaseController {
|
||||
|
||||
do {
|
||||
print("builtInUltraWideCamera:\(frontCamera.videoZoomFactor)")
|
||||
// try frontCamera.lockForConfiguration()
|
||||
// frontCamera.videoZoomFactor = 8.0//变焦
|
||||
// frontCamera.unlockForConfiguration()
|
||||
|
||||
// 设置焦距
|
||||
// frontCamera.focusMode = .autoFocus
|
||||
ultraWideCameraDeviceInput = try AVCaptureDeviceInput(device: frontCamera)
|
||||
@ -468,9 +469,14 @@ class CCSpatialShootController: BaseController {
|
||||
// // view.layer.addSublayer(ultraWideCameraVideoPreviewLayer)
|
||||
// self.view.layer.insertSublayer(ultraWideCameraVideoPreviewLayer, at: 0)
|
||||
// }
|
||||
|
||||
DispatchQueue.global().async {
|
||||
self.session.startRunning()
|
||||
|
||||
//变焦设置需要在AVCaptureMultiCamSession statrunning之后设置才会生效
|
||||
try! frontCamera.lockForConfiguration()
|
||||
frontCamera.videoZoomFactor = 1.75//变焦
|
||||
frontCamera.unlockForConfiguration()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -589,6 +595,20 @@ class CCSpatialShootController: BaseController {
|
||||
//拍照
|
||||
@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
|
||||
|
||||
imgs.removeAllObjects()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user