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