如何在AVCaptureVideoPreviewLayer
内获取图片尺寸:
self.cameraPreviewLayer.frame = self.cameraView.frame; // (0.0, 0.0, 320.0, 568.0)
小于帧的AVCaptureVideoPreviewLayer
内的图像。
答案 0 :(得分:4)
您无法在AVCaptureVideoPreviewLayer
框架内获得实际渲染的尺寸。你必须计算它。
以下是获取实际视频尺寸的方法:
AVCaptureDeviceInput *videoDeviceInput = // initialised already in your app
// Here you can get the video dimensions:
CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions(videoDeviceInput.device.activeFormat.formatDescription);
从这里你可以在AVCaptureVideoPreviewLayer
框架内计算方面拟合矩形。
答案 1 :(得分:0)
快捷代码
var captureSession : AVCaptureSession?
var captureInput : AVCaptureDeviceInput?{
get{
return self.captureSession?.inputs.first as? AVCaptureDeviceInput
}
}
func doSomething(){
guard let captureInput = captureInput else{ return }
let dims : CMVideoDimensions = CMVideoFormatDescriptionGetDimensions(captureInput.device.activeFormat.formatDescription)
//do whatever
}