首先,我知道很多人都提出了类似的问题 - 但我找不到任何相似的问题。
调用此界面时:
- (void) captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
{
CVImageBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CVPixelBufferLockBaseAddress(pixelBuffer, 0);
// get buffer dimensions
size_t bufferHeight = CVPixelBufferGetHeight(pixelBuffer);
size_t bufferWidth = CVPixelBufferGetWidth(pixelBuffer);
...
当手机处于"纵向模式" 时 - 我的身高 480 ,宽度 640 。
奇怪的是 - 当我检查[connection videoOrientation]
时,它被正确设置为肖像。
谢谢
@Gabriel: 我已经有了这段代码:
-(void) viewWillLayoutSubviews
{
// Handle camera
if (_videoPreviewLayer)
{
_videoPreviewLayer.frame = self.view.bounds;
for (AVCaptureOutput* outcap in _captureSession.outputs)
{
for(AVCaptureConnection* con in outcap.connections)
{
switch ([[UIDevice currentDevice] orientation])
{
case UIInterfaceOrientationPortrait:
[con setVideoOrientation:AVCaptureVideoOrientationPortrait];
break;
case UIInterfaceOrientationLandscapeRight:
[con setVideoOrientation:AVCaptureVideoOrientationLandscapeRight]; //home button on right. Refer to .h not doc
break;
case UIInterfaceOrientationLandscapeLeft:
[con setVideoOrientation:AVCaptureVideoOrientationLandscapeLeft]; //home button on left. Refer to .h not doc
break;
case UIInterfaceOrientationPortraitUpsideDown:
[con setVideoOrientation:AVCaptureVideoOrientationPortraitUpsideDown]; //home button on left. Refer to .h not doc
break;
default:
[con setVideoOrientation:AVCaptureVideoOrientationPortrait]; //for portrait upside down. Refer to .h not doc
break;
}
}
}
}
}
正如我上面提到的,当检查连接时 - 它是正确的方向,图像虽然是错误的方向..
您是否通过手动修复它 - 使用我将使用的方法,自动更改为正确的方向?
问题在于显示效果好,只是拍照...
答案 0 :(得分:4)
解决你的问题:
1 - 检查您是否已禁用或修改了方向模式。
2 - 使用AVFoundation时,您必须自己旋转图像,这是我使用的代码:
AVCaptureVideoOrientation newOrientation;
switch ([[UIDevice currentDevice] orientation]) {
case UIDeviceOrientationPortrait:
newOrientation = AVCaptureVideoOrientationPortrait;
break;
case UIDeviceOrientationPortraitUpsideDown:
newOrientation = AVCaptureVideoOrientationPortraitUpsideDown;
break;
case UIDeviceOrientationLandscapeLeft:
newOrientation = AVCaptureVideoOrientationLandscapeRight;
break;
case UIDeviceOrientationLandscapeRight:
newOrientation = AVCaptureVideoOrientationLandscapeLeft;
break;
default:
newOrientation = AVCaptureVideoOrientationPortrait;
}
3 - 使用上面的代码
希望这有帮助。
答案 1 :(得分:0)
行...
这太超级奇怪!!!
当默认应用程序方向为横向右侧时 - 它不起作用。
当我将默认应用程序方向更改为纵向(底部的按钮)时 - 它突然开始工作......
我想知道这是一个错误还是预期的行为......