VideoPreviewLayer를 iPhone의 전체 화면을 채우는 방법에 대해 약 백만 개의 스레드를 읽었지만 아무 것도 작동하지 않습니다 ... 어쩌면 당신이 정말로 붙어서 나를 도울 수 있습니다.AVCaptureVideoPreviewLayer가 화면을 채우지 못함
이 내 미리 층 초기화입니다 :
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
// Choosing bigger preset for bigger screen.
_sessionPreset = AVCaptureSessionPreset1280x720;
}
else
{
_sessionPreset = AVCaptureSessionPresetHigh;
}
[self setupAVCapture];
AVCaptureSession *captureSession = _session;
AVCaptureVideoPreviewLayer *previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:captureSession];
UIView *aView = self.view;
previewLayer.frame = aView.bounds;
previewLayer.connection.videoOrientation = AVCaptureVideoOrientationLandscapeRight;
[aView.layer addSublayer:previewLayer];
내 setupAvCapture 방법입니다 :
//-- Setup Capture Session.
_session = [[AVCaptureSession alloc] init];
[_session beginConfiguration];
//-- Set preset session size.
[_session setSessionPreset:_sessionPreset];
//-- Creata a video device and input from that Device. Add the input to the capture session.
AVCaptureDevice * videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if(videoDevice == nil)
assert(0);
//-- Add the device to the session.
NSError *error;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&error];
if(error)
assert(0);
[_session addInput:input];
//-- Create the output for the capture session.
AVCaptureVideoDataOutput * dataOutput = [[AVCaptureVideoDataOutput alloc] init];
[dataOutput setAlwaysDiscardsLateVideoFrames:YES]; // Probably want to set this to NO when recording
//-- Set to YUV420.
[dataOutput setVideoSettings:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_420YpCbCr8BiPlanarFullRange]
forKey:(id)kCVPixelBufferPixelFormatTypeKey]]; // Necessary for manual preview
// Set dispatch to be on the main thread so OpenGL can do things with the data
[dataOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()];
[_session addOutput:dataOutput];
[_session commitConfiguration];
[_session startRunning];
가 이미 AVCaptureSessionPresets 및 ResizeFit 옵션 다른를 사용했습니다. 그러나 항상 다음과 같습니다
http://imageshack.us/photo/my-images/707/img0013g.png/
또는를이 내가 사용하는 경우 previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; 레이어의 크기를 기록하면 올바른 전체 화면 크기가 반환됩니다.
http://imageshack.us/photo/my-images/194/img0014k.png/
previewLayer.frame = CGRectMake (0, 0, 1280, 720)를 설정하면; 수동으로 작동 중입니다 ... 아무도 그것을 설명 할 수 있습니까? 너비/높이가 뒤집 혔지만 세로 방향은 실제로 가로 방향입니다. 그래서 구현 _screenWidth = [UIScreen mainScreen] .bounds.size.width; _screenHeight = [UIScreen mainScreen] .bounds.size.height; if (_screenHeight> _screenWidth) { _screenWidth = _screenHeight; _screenHeight = [UIScreen mainScreen] .bounds.size.width; } – user2135074