0

I'm running AVCaptureSession to get still images from it on user action (button press). I've a problem with the orientation rotated by 90 degree although I set those values :

- (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];
}

And

- (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];
        }
    }];

Thanks in Advance

OXXY
  • 1,047
  • 2
  • 18
  • 43
  • Try this, I think this is the same issue. http://stackoverflow.com/questions/3561738/why-avcapturesession-output-a-wrong-orientation – Dhaval Patel Aug 08 '16 at 13:02
  • My application is Portrait and I set the session orientation and still Image Orientation to Portrait and the outputed image orientation to UIImageOrientationUp ! but the Image is rotated to right – OXXY Aug 08 '16 at 13:08
  • Did you ever get this working, I appear to be having a similar issue. – BarrettJ Oct 19 '16 at 16:57
  • Yes !, Use the landscape right orientation ! – OXXY Oct 26 '16 at 09:28

1 Answers1

0

Try with UIImageOrientationLeft orientation.

Dhaval Patel
  • 95
  • 12