gpt4 book ai didi

ios - AVCaptureSession 和预览层不填满整个屏幕

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:57:27 24 4
gpt4 key购买 nike

所以,我尝试在我的应用程序中使用手机上的摄像头,我成功了,但不幸的是,在使用预览时,图层没有填满整个屏幕 Here is an image to show you what it looks like

这是我的代码:

if let previewLayer = AVCaptureVideoPreviewLayer(session: captureSession) {
self.previewLayer = previewLayer
self.view.layer.addSublayer(self.previewLayer)
self.previewLayer.frame = self.view.layer.frame
captureSession.startRunning()

let dataOutput = AVCaptureVideoDataOutput()
dataOutput.videoSettings = [(kCVPixelBufferPixelFormatTypeKey as NSString):NSNumber(value:kCVPixelFormatType_32BGRA)]

dataOutput.alwaysDiscardsLateVideoFrames = true

if captureSession.canAddOutput(dataOutput) {
captureSession.addOutput(dataOutput)
}

captureSession.commitConfiguration()


let queue = DispatchQueue(label: "com.Osmo.captureQueue")
dataOutput.setSampleBufferDelegate(self, queue: queue)
}

最佳答案

这可能是因为您试图从具有自动布局约束的 View 中设置预览图层的框架。尝试将 viewDidLayoutSubviews 方法的覆盖添加到您的 View Controller :

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
self.previewLayer.frame = self.view.layer.bounds
}

关于ios - AVCaptureSession 和预览层不填满整个屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42348237/

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