gpt4 book ai didi

iphone - AvCam iOS 6 中的风景

转载 作者:行者123 更新时间:2023-12-03 20:51:52 26 4
gpt4 key购买 nike

我是 iOS 新手,正在尝试使用 AvCam 创建自定义相机。我在获取横向预览时遇到问题 - 它会将 View 顺时针旋转 90 度并在半个屏幕上显示。

我收到此消息 -

WARNING: -[ setOrientation:] is deprecated.

请使用 AVCaptureConnection 的 -setVideoOrientation:

AVCaptureConnection 已经设置了方向,所以我不知道我还应该做什么。

我知道这个问题在以前的 iOS 版本(4,5)中被问过很多次,但这些技术/代码都不适合我(iOS 6)。

原始代码(Apple 未进行任何更改)

if ([self captureManager] == nil) {
AVCamCaptureManager *manager = [[AVCamCaptureManager alloc] init];
[self setCaptureManager:manager];
[manager release];

[[self captureManager] setDelegate:self];

if ([[self captureManager] setupSession]) {
// Create video preview layer and add it to the UI
AVCaptureVideoPreviewLayer *newCaptureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:[[self captureManager] session]];


UIView *view = [self videoPreviewView];
CALayer *viewLayer = [view layer];
[viewLayer setMasksToBounds:YES];

CGRect bounds = [view bounds];
[newCaptureVideoPreviewLayer setFrame:bounds];

if ([newCaptureVideoPreviewLayer isOrientationSupported]) {
[newCaptureVideoPreviewLayer setOrientation:AVCaptureVideoOrientationPortrait];
}



[newCaptureVideoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];

[viewLayer insertSublayer:newCaptureVideoPreviewLayer below:[[viewLayer sublayers] objectAtIndex:0]];

[self setCaptureVideoPreviewLayer:newCaptureVideoPreviewLayer];

AVCaptureConnection block :

-(void)startRecordingWithOrientation:(AVCaptureVideoOrientation)videoOrientation; {
AVCaptureConnection *videoConnection = [AVCamUtilities connectionWithMediaType:AVMediaTypeVideo fromConnections:[[self movieFileOutput] connections]];
if ([videoConnection isVideoOrientationSupported])
[videoConnection setVideoOrientation:videoOrientation];

[[self movieFileOutput] startRecordingToOutputFileURL:[self outputFileURL] recordingDelegate:self];

}

最佳答案

上次我也偶然发现了这个问题。我通过做两件事解决了这个问题

  1. 获得正确的方向
    替换

    if ([newCaptureVideoPreviewLayer isOrientationSupported]) {
    [newCaptureVideoPreviewLayer setOrientation:AVCaptureVideoOrientationPortrait];
    }

    if ([newCaptureVideoPreviewLayer.connection isVideoOrientationSupported]) {  
    [newCaptureVideoPreviewLayer.connection setVideoOrientation:[UIDevice currentDevice].orientation];
    }
  2. 在初始化期间强制更新视频方向,以通过触发捕获横向模式下的视频输出- (void)deviceOrientationDidChangeAVCaptureManager.m 中手动进行

    我将其添加到:

    - (BOOL) setupSession
    {
    BOOL success = NO;

    ...

    AVCamRecorder *newRecorder = [[AVCamRecorder alloc] initWithSession:[self session] outputFileURL:self.lastOutputfileURL];
    [newRecorder setDelegate:self];

    [self performSelector:@selector(deviceOrientationDidChange)];

    ...

    return success;
    }

关于iphone - AvCam iOS 6 中的风景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12966175/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com