2

I am using AVFoundation to capture still images progmatically with the front camera in the portrait orientation camera view in a UIViewController. This is all good.

The problem I have is when I display the pictures I took in the current session inside the UIImageView through animation all the pictures are being displayed as landscape left, I need the pictures to be displayed in the orientation they were taken in which is portrait.

I have tried forcing the device/image orientation to portrait Up but have not had any luck.

Would be great if someone can tell me where I am going wrong. Thank you

I have included my code snippets below.

//Take picture and store images taken to mutable array

-(void)takePicture {

AVCaptureConnection *videoConnection = nil;
for (AVCaptureConnection *connection in stillImageOutput.connections)
{
    for (AVCaptureInputPort *port in [connection inputPorts])
    {
        if ([[port mediaType] isEqual:AVMediaTypeVideo] )
        {
            videoConnection = connection;
            break;
        }
    }
    if (videoConnection) { break; }
}

NSLog(@"about to request a capture from: %@", stillImageOutput);  
[stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error)
 {
     if ([videoConnection isVideoOrientationSupported])
         [videoConnection setVideoOrientation:[UIDevice currentDevice].orientation];

     CFDictionaryRef exifAttachments = CMGetAttachment( imageSampleBuffer, kCGImagePropertyExifDictionary, NULL);
     if (exifAttachments)
     {
         // Do something with the attachments.
         NSLog(@"attachements: %@", exifAttachments);
     }
     else
         NSLog(@"no attachments");

     NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
     UIImage *image = [[UIImage alloc] initWithData:imageData];

     UIImage *orientedImage= [[UIImage alloc] initWithCGImage: image.CGImage scale:1.0 orientation:UIImageOrientationUp];
     NSLog(@"the image oreintation is %i", orientedImage.imageOrientation);

     [photosTakenArray addObject:orientedImage];

...

This is how I am displaying the images the camera took inside another UIViewController using the UIImageView startAnimating function. This is where issue is of the pictures taken by camera all being displayed landscape left. photoViewer is my UIImageView in this case and photosToShow is an NSArray reference to the photosTakenArray above.

if ([photosToShow count]>0) {

    NSLog(@"we have %i photos to display", [photosToShow count]);
    photoViewer.animationImages = photosToShow;

    // all frames will execute in 1.75 seconds
    photoViewer.animationDuration = 1.75;
    // repeat the annimation forever
    photoViewer.animationRepeatCount = 0;
    // start animating
    [photoViewer startAnimating];

...

flex007
  • 143
  • 1
  • 4
  • 10

1 Answers1

0

I also faced the same problem then i changed my code in delegate imagePickerController

-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
{
    //NSLog(@"%@",info);

    dataImage = UIImageJPEGRepresentation([info objectForKey:@"UIImagePickerControllerOriginalImage"],1);
 }  

Hope this will help you

Rajneesh071
  • 30,846
  • 15
  • 61
  • 74
  • I'm not actually using a ImagePickerController but holding images in an array, so did not give this a try. The above post link posted by Muhaye had the simple solution that worked for me. – flex007 Dec 12 '12 at 10:41
  • Yup that was for rotating your image, but i did this task by replacing with this line in my code....or you can flip using UIImage *flipped = [UIImage imageWithCGImage:imag.CGImage scale:1.0 orientation:UIImageOrientationDown]; – Rajneesh071 Dec 12 '12 at 12:15