Not able to show the Image in proper format from camera in landscape mode
Asked Answered
E

6

10

I am working on iPad App in Ios6, There when we click the right bar button i am giving an action like below:

-(IBAction)camerabuttonAction:(id)sender
{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.delegate = self;

   self.popoverController = [[UIPopoverController alloc] initWithContentViewController:picker];
   [self.popoverController presentPopoverFromRect:CGRectMake(50, -250, 500, 300) inView:appDelegate.splitview.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}

My problem is, When i am in Land scape mode if i click the button. The camera show in portrait mode(Image appears in reverse mode to see) after every second use. But, if i shake the iPad then it shows in LandScape i.e, in correct direction .

see the below images

When i am in Land scape mode if i click the button camera shows the image like below:

enter image description here

if i shake the iPad then camera shows the image like below:

enter image description here

I have tried a lot and googled,but I did not find any solution. It's killing my time so if any one have worked on it please guide me and post sample code.

Eggnog answered 22/3, 2013 at 5:51 Comment(5)
What exact version of iOS6 are you seeing this on? I cannot reproduce this behaviour on iOS6.1.2/ipadMini or iOS6.1.3/ipadMini.Porbeagle
https://mcmap.net/q/282792/-how-to-use-uiimagepickercontroller-in-an-app-which-support-landscape-orientation-only-in-ios-6Paedo
[picker willAnimateRotationToInterfaceOrientation:[UIApplication sharedApplication].statusBarOrientation duration:0]; Try adding this codeHeadset
or else try adding your UIImagePickerController into UINavigationController. Then add your navigationController into pop over controller and check again.Headset
we all are waiting for your response buddy .. Does nothing helped you :( ? @Harini GouthamPaedo
M
9

You can try giving transform to your imagePickerController

imagePickerController.view.transform = CGAffineTransformMakeRotation(-M_PI/2);
Malonis answered 26/3, 2013 at 11:0 Comment(2)
even i was facing the same problem. This transform code really helped.Ammadas
Worked. Use M_PI_2 though, instead of M_PI/2.Stringendo
A
10

I faced the same issue in my project i have tried the below and works for me

My code:

- (UIImage *)scaleAndRotateImage:(UIImage *)image {
    int kMaxResolution = 640; // Or whatever

    CGImageRef imgRef = image.CGImage;

    CGFloat width = CGImageGetWidth(imgRef);
    CGFloat height = CGImageGetHeight(imgRef);


    CGAffineTransform transform = CGAffineTransformIdentity;
    CGRect bounds = CGRectMake(0, 0, width, height);
    if (width > kMaxResolution || height > kMaxResolution) {
        CGFloat ratio = width/height;
        if (ratio > 1) {
            bounds.size.width = kMaxResolution;
            bounds.size.height = roundf(bounds.size.width / ratio);
        }
        else {
            bounds.size.height = kMaxResolution;
            bounds.size.width = roundf(bounds.size.height * ratio);
        }
    }

    CGFloat scaleRatio = bounds.size.width / width;
    CGSize imageSize = CGSizeMake(CGImageGetWidth(imgRef), CGImageGetHeight(imgRef));
    CGFloat boundHeight;
    UIImageOrientation orient = image.imageOrientation;
    switch(orient) {

        case UIImageOrientationUp: //EXIF = 1
            transform = CGAffineTransformIdentity;
            break;

        case UIImageOrientationUpMirrored: //EXIF = 2
            transform = CGAffineTransformMakeTranslation(imageSize.width, 0.0);
            transform = CGAffineTransformScale(transform, -1.0, 1.0);
            break;

        case UIImageOrientationDown: //EXIF = 3
            transform = CGAffineTransformMakeTranslation(imageSize.width, imageSize.height);
            transform = CGAffineTransformRotate(transform, M_PI);
            break;

        case UIImageOrientationDownMirrored: //EXIF = 4
            transform = CGAffineTransformMakeTranslation(0.0, imageSize.height);
            transform = CGAffineTransformScale(transform, 1.0, -1.0);
            break;

        case UIImageOrientationLeftMirrored: //EXIF = 5
            boundHeight = bounds.size.height;
            bounds.size.height = bounds.size.width;
            bounds.size.width = boundHeight;
            transform = CGAffineTransformMakeTranslation(imageSize.height, imageSize.width);
            transform = CGAffineTransformScale(transform, -1.0, 1.0);
            transform = CGAffineTransformRotate(transform, 3.0 * M_PI / 2.0);
            break;

        case UIImageOrientationLeft: //EXIF = 6
            boundHeight = bounds.size.height;
            bounds.size.height = bounds.size.width;
            bounds.size.width = boundHeight;
            transform = CGAffineTransformMakeTranslation(0.0, imageSize.width);
            transform = CGAffineTransformRotate(transform, 3.0 * M_PI / 2.0);
            break;

        case UIImageOrientationRightMirrored: //EXIF = 7
            boundHeight = bounds.size.height;
            bounds.size.height = bounds.size.width;
            bounds.size.width = boundHeight;
            transform = CGAffineTransformMakeScale(-1.0, 1.0);
            transform = CGAffineTransformRotate(transform, M_PI / 2.0);
            break;

        case UIImageOrientationRight: //EXIF = 8
            boundHeight = bounds.size.height;
            bounds.size.height = bounds.size.width;
            bounds.size.width = boundHeight;
            transform = CGAffineTransformMakeTranslation(imageSize.height, 0.0);
            transform = CGAffineTransformRotate(transform, M_PI / 2.0);
            break;

        default:
            [NSException raise:NSInternalInconsistencyException format:@"Invalid image orientation"];

    }

    UIGraphicsBeginImageContext(bounds.size);

    CGContextRef context = UIGraphicsGetCurrentContext();

    if (orient == UIImageOrientationRight || orient == UIImageOrientationLeft) {
        CGContextScaleCTM(context, -scaleRatio, scaleRatio);
        CGContextTranslateCTM(context, -height, 0);
    }
    else {
        CGContextScaleCTM(context, scaleRatio, -scaleRatio);
        CGContextTranslateCTM(context, 0, -height);
    }

    CGContextConcatCTM(context, transform);

    CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, width, height), imgRef);
    UIImage *imageCopy = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return imageCopy;
}
Andorra answered 29/3, 2013 at 11:3 Comment(0)
M
9

You can try giving transform to your imagePickerController

imagePickerController.view.transform = CGAffineTransformMakeRotation(-M_PI/2);
Malonis answered 26/3, 2013 at 11:0 Comment(2)
even i was facing the same problem. This transform code really helped.Ammadas
Worked. Use M_PI_2 though, instead of M_PI/2.Stringendo
V
2

I study about your issue in Google search and got some result or possibility like bellow point:-

result 1

some Answer say's that its a iOS 6 bug so you can not fixed It like bellow Quetion:-

iPad camera popover preview wrong rotation and scale

result 2

I don't think we can control orientation of camera.Camera orientation property is inbuilt,which changes with orientation of device.

iPad camera orientation portrait mode?

result 3

you can manage Scaled live iPhone Camera view in center physically move the picker frame. by Bellow code:-

[picker.view setFrame:CGRectMake(xOffset,yOffset,picker.view.frame.size.width,picker.view.frame.size.height)];

hope you got actually solution. about this bug or issue

Vaporization answered 23/3, 2013 at 7:56 Comment(2)
Actually my orientation issue is...When I turns the Ipad the camera shows in wrong orientation..But after detecting the face..Its coming into the correct orientation.. @nitinEggnog
check this for ios6 oriation :-#12650637Vaporization
C
1

I'm going to try a good guess here because I haven't done this myself...

Have you tried to create a subclass of UIImagePickerController and implement the methods of the interfaceOrientation from the ViewController (which is the super class)?

Chyme answered 26/3, 2013 at 10:50 Comment(0)
D
1

Please try this

[popController presentPopoverFromRect:CGRectMake(1024, 
  self.view.bounds.origin.y + (self.view.bounds.size.height / 2), 1, 1) 
inView:self.view 
permittedArrowDirections:UIPopoverArrowDirectionRight 
animated:YES];
Distaste answered 26/3, 2013 at 11:20 Comment(0)
T
1

I have an ipad app only lanscape mode, I was freaking out because I read all these posts but I used this very simple code to take a picture and it works perfectly for my only lanscape app. Important I don´t choose an image from the library, I just take the picture and use it to put it over an other image, it works for me perfectly.

if ([UIImagePickerController isSourceTypeAvailable:
         UIImagePickerControllerSourceTypeCamera])
    {

        UIImagePickerController *imagePicker =
        [[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.sourceType =
        UIImagePickerControllerSourceTypeCamera;
        imagePicker.mediaTypes = [NSArray arrayWithObjects:
                                  (NSString *) kUTTypeImage,
                                  nil];
        imagePicker.allowsEditing = NO;
        [self presentViewController:imagePicker
                                animated:YES completion:nil];
       // [imagePicker release];
        newMedia = YES;
    }

-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [self.popoverController dismissPopoverAnimated:true];
  //  [popoverController release];

    NSString *mediaType = [info
                           objectForKey:UIImagePickerControllerMediaType];
    [self dismissViewControllerAnimated:YES completion:nil];
    if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
        UIImage *image = [info
                          objectForKey:UIImagePickerControllerOriginalImage];

        imageView.image = image;
        if (newMedia)
            UIImageWriteToSavedPhotosAlbum(image,
                                           self,
                                           @selector(image:finishedSavingWithError:contextInfo:),
                                           nil);
    }
    else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie])
    {
        // Code here to support video if enabled
    }
}
Telic answered 18/6, 2013 at 18:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.