【发布时间】:2014-06-17 08:39:16
【问题描述】:
首先,我知道很多人都问过类似的问题 - 但我找不到任何类似的问题。
调用该接口时:
- (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] 时,它被正确设置为纵向。
- 为什么连接方向不影响采样缓冲区?
- 我应该自己旋转图像吗?
- 有没有办法将样本配置为由设备方向给出?
谢谢
@加布里埃尔: 我已经有了这个代码:
-(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;
}
}
}
}
}
正如我上面提到的,在检查连接时 - 它是正确的方向,图像虽然是错误的方向..
您是否通过手动修复它进行参考 - 我将使用什么方法自动更改为正确的方向?
关键是显示器不错,就是拍照而已……
【问题讨论】:
标签: ios objective-c avfoundation