The "problem" is the image orientation, iOS camera returns images only in one orientation, except if you set the -videoOrientation
property that transform already the image taken. So there can be different problems:
videoOrientation
non set correctlyvideoOrientation
not set at ALL
The videoOrientation property works only for still images and video capturing, not for single buffers.
This snippet is tanken from Apple AVCam sample code.
[[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo] setVideoOrientation:[[(AVCaptureVideoPreviewLayer *)[[self previewView] layer] connection] videoOrientation]];
[AVCamViewController setFlashMode:AVCaptureFlashModeAuto forDevice:[[self videoDeviceInput] device]];
[[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo] completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
if (imageDataSampleBuffer)
{
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
UIImage *image = [[UIImage alloc] initWithData:imageData];
[[[ALAssetsLibrary alloc] init] writeImageToSavedPhotosAlbum:[image CGImage] orientation:(ALAssetOrientation)[image imageOrientation] completionBlock:nil];
}
}]; <br>
First it sets the orientation according to the preview view, later it takes the shot, and later it saves it on the asset library with correct orientation