所以,我試圖在我的應用程序中使用手機上的相機,並且我成功了,但不幸的是,當使用預覽時,圖層不會填滿整個屏幕Here is an image to show you what it looks likeAVCaptureSession和預覽圖層不會填充整個屏幕
這裏是我的代碼:
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)
}
嘗試設置'self.view.layer.bounds'代替 –
對不起,沒有工作。還有什麼我可以做的嗎? –
你在哪裏調用這段代碼? –