gpt4 book ai didi

ios - 为什么当 UIImagePickerController 处于视频模式时,AVFoundation 显示与 UIImagePickerController 相同的缩放级别?

转载 作者:行者123 更新时间:2023-11-29 10:20:37 30 4
gpt4 key购买 nike

为什么当 UIImagePickerController 处于视频模式时,AVFoundation 显示的缩放级别与 UIImagePickerController 相同?如何使 AVFoundation 在照片模式下以与 UIImagePickerController 相同的缩放级别显示?

AVFoundation

UIImagePickerController

import UIKit
import AVFoundation
class ViewController: UIViewController {
var captureSession = AVCaptureSession()
var sessionOutput = AVCapturePhotoOutput()
var sessionOutputSetting = AVCapturePhotoSettings(format: [AVVideoCodecKey: AVVideoCodecJPEG])
var previewLayer = AVCaptureVideoPreviewLayer()
var cameraView: UIView?
override func viewDidLoad() {
cameraView = UIView(frame: view.frame)
view.addSubview(cameraView!)
}
override func viewWillAppear(_ animated: Bool) {
let deviceDiscoverySession = AVCaptureDeviceDiscoverySession(deviceTypes: [.builtInDualCamera, .builtInTelephotoCamera, .builtInWideAngleCamera], mediaType: AVMediaTypeVideo, position: .unspecified)
for device in (deviceDiscoverySession?.devices)! {
if device.position == .back {
do {
let input = try AVCaptureDeviceInput(device: device)
if captureSession.canAddInput(input) {
captureSession.addInput(input)

if captureSession.canAddOutput(sessionOutput) {
captureSession.addOutput(sessionOutput)
previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
previewLayer.frame = (cameraView?.bounds)!
previewLayer.videoGravity = AVLayerVideoGravityResizeAspect // AVLayerVideoGravityResizeAspectFill
previewLayer.connection.videoOrientation = .portrait
cameraView?.layer.addSublayer(previewLayer)
}
}
} catch {
print("exception!")
}
}
}
}
override func viewDidAppear(_ animated: Bool) {
captureSession.startRunning()
}
override var shouldAutorotate: Bool {
return false
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .portrait
}
}

最佳答案

两个 View 的纵横比不同。顶 View 用视频填充屏幕,并且剪辑了一些视频。而第二个视频没有。一般来说,视频的标准输出是 4:3 宽高比。您可以通过枚举 AVCaptureDeviceFormat 或您的 AVCaptureDevice 来验证这一点。调整 cameraView 的大小,使其具有相同的纵横比,并且您应该获得相同的缩放级别。

关于ios - 为什么当 UIImagePickerController 处于视频模式时,AVFoundation 显示与 UIImagePickerController 相同的缩放级别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43881405/

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