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

后端 未结 6 914
我寻月下人不归
我寻月下人不归 2020-12-17 19:56

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
{
    U         


        
相关标签:
6条回答
  • 2020-12-17 20:18

    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
        }
    }
    
    0 讨论(0)
  • 2020-12-17 20:27

    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;
    }
    
    0 讨论(0)
  • 2020-12-17 20:29

    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

    0 讨论(0)
  • 2020-12-17 20:30

    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)?

    0 讨论(0)
  • 2020-12-17 20:32

    You can try giving transform to your imagePickerController

    imagePickerController.view.transform = CGAffineTransformMakeRotation(-M_PI/2);
    
    0 讨论(0)
  • 2020-12-17 20:36

    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];
    
    0 讨论(0)
提交回复
热议问题