0

I want to add a custom overlay view over UIImagePickerController, this overlay view only supports Landscape mode. I only want the UIImagePickerController to take pictures in Landscape mode. Is there any way I can achieve this...?

Ankit Srivastava
  • 12,347
  • 11
  • 63
  • 115
  • http://stackoverflow.com/questions/14484816/force-uiimagepickercontroller-to-take-photo-in-portrait-orientation-dimensions-i ... i think fr the landscape thingy ull find out then ? – IronManGill Aug 02 '13 at 10:31
  • Possible duplicate of http://stackoverflow.com/questions/5737632/open-uiimagepickercontroller-in-landscape-mode – Maulik Aug 02 '13 at 14:12
  • possible duplicate of [Force landscape orientation in UIImagePickerController](http://stackoverflow.com/questions/14618546/force-landscape-orientation-in-uiimagepickercontroller) – Hemang Jun 25 '14 at 05:57

2 Answers2

0

I created two different overlays with two separate methods, calling whichever matched up to the orientation.

- (IBAction)takePicture:(id)sender {

[[UIDevice currentDevice]beginGeneratingDeviceOrientationNotifications];

if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation)) {


    [self portraitDisplayOverlay];

}else{

    [self startCameraControllerFromViewController:self usingDelegate:self];


   }
}

On the portrait overlay I set the UIImagePickerController property to hide camera controls

picker.showCameraControls = NO;

This overlay simply instructed the user to use Landscape mode, when it tilts to landscape call the proper overlay and voila.

Hope this helps, Jim.

Jim Tierney
  • 4,078
  • 3
  • 27
  • 48
0

Please Read the Apple documentation that says UIImagePickerController class supports portrait mode only:Click Here

be noted that if you call UIImagePickerController in Landscape mode, your app is possible to be rejected by Apple

you have to find another way like create the custom camera USing the AVFoundation framework

or

try this method Pass your taken image into a method like this

// Code from: http://discussions.apple.com/thread.jspa?messageID=7949889
- (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;
}
nivritgupta
  • 1,966
  • 2
  • 20
  • 38
  • i am also create one of Example in which camera is open in landscape mode and also capture the picture in landscape mode only – nivritgupta Aug 02 '13 at 12:48