[英]iOS app camera orientation in captureOutput
首先,我知道很多人都问过类似的问题-但我找不到类似的问题。
调用此接口时:
- (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;
}
}
}
}
}
并且如上所述,在检查连接时-方向正确,但图像方向错误。
您是否通过手动修复来引用-我将使用哪种方法自动将其更改为正确的方向?
问题是显示效果很好,这只是拍照...
解决您的问题:
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-使用上面的代码
希望这可以帮助。
好...
真是太不可思议了!!!
当默认的应用程序方向为“横向正确”时-它不起作用。
当我将默认应用程序方向更改为纵向(底部的按钮)时,它突然开始工作...
我想知道这是错误还是预期的行为...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.