AVCaptureStillImageOutput Ориентация изображения неверна

Я запускаю AVCaptureSession, чтобы получать от него неподвижные изображения при действии пользователя (нажатие кнопки). У меня проблема с ориентацией, повернутой на 90 градусов, хотя я установил эти значения:

- (void)setupAVCapture {
    //Capture session
    _session = nil;
    _session = [[AVCaptureSession alloc] init];
    [_session setSessionPreset:AVCaptureSessionPreset1280x720];
//preview view
    self.previewLayer = nil;
    self.previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:_session];
    [self.previewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];

    CALayer *rootLayer = [_previewView layer];
    [rootLayer setMasksToBounds:YES];
    [[_previewLayer connection]setVideoOrientation:AVCaptureVideoOrientationPortrait];
}

И

- (IBAction)captureImage:(id)sender {

    AVCaptureConnection *stillImageConnection = [stillImageOutput connectionWithMediaType:AVMediaTypeVideo];
    [stillImageConnection setVideoOrientation:AVCaptureVideoOrientationPortrait];
    [stillImageOutput captureStillImageAsynchronouslyFromConnection:stillImageConnection completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
        if (imageDataSampleBuffer != nil) {
            NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
            CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData((CFDataRef)imageData);
            CGImageRef cgImageRef = CGImageCreateWithJPEGDataProvider
            (dataProvider, nil, YES, kCGRenderingIntentDefault);

            _capturedImage = [UIImage imageWithCGImage:cgImageRef scale:1.0 orientation:UIImageOrientationUp];
        }
    }];

Заранее спасибо


person OXXY    schedule 08.08.2016    source источник


Ответы (1)


Попробуйте с ориентацией UIImageOrientationLeft.

person Dhaval Patel    schedule 08.08.2016
comment
в качестве параметра для imageWithCGImage ? - person OXXY; 08.08.2016