不能从相机显示正确的格式图像在横向模式(Not able to show the Image in

2019-07-22 14:16发布

我工作的iPad应用程序在iOS6的,还有当我们点击右边栏按钮我给像下面的操作:

-(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];
}

我的问题是,当我在景观模式下,如果我按一下按钮。 摄像机显示在纵向模式(图像出现在反向模式看)每一秒后使用。 但是,如果我动摇iPad的话,就说明在景观即在正确方向。

看到下面的图片

当我在景观模式下,如果我按一下按钮相机显示如下图:

如果我摇在iPad然后相机显示像下面的图片:

我已经尝试了很多,一派,但我没有找到任何解决方案。 它的杀了我的时间,因此,如果任何人有它的工作,请指引我和张贴的示例代码。

Answer 1:

你可以尝试给转变为您imagePickerController

imagePickerController.view.transform = CGAffineTransformMakeRotation(-M_PI/2);


Answer 2:

我面临着同样的问题,在我的项目我已经尝试了以下和对我的作品

我的代码:

- (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;
}


Answer 3:

我研究关于在谷歌搜索您的问题,并得到了一些结果或可能像波纹管点: -

结果1

有的回答说的是它是一个iOS 6的bug,因此你可以不固定它像波纹管Quetion: -

iPad的摄像头酥料饼预览错误的旋转和缩放

结果2

我不认为我们能控制camera.Camera方位性的取向是内在的,这与设备的方向变化。

iPad的相机方向肖像模式?

结果3

您可以在管理中心实时鳞甲iPhone相机视图物理移动拾取框。 贝娄代码: -

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

希望你实际上得到解决。 有关此错误或问题



Answer 4:

我要在这里尝试一个很好的猜测,因为我没有这个做我自己......

您是否尝试过创建的UIImagePickerController的一个子类,并实现从视图控制器(这是超类)的interfaceOrientation的方法呢?



Answer 5:

请试试这个

[popController presentPopoverFromRect:CGRectMake(1024, 
  self.view.bounds.origin.y + (self.view.bounds.size.height / 2), 1, 1) 
inView:self.view 
permittedArrowDirections:UIPopoverArrowDirectionRight 
animated:YES];


Answer 6:

我有一个iPad应用程序只lanscape模式,我被吓坏了,因为我读这些文章,但我用这个非常简单的代码来拍照,它完全适用于我的唯一lanscape应用程序。 重要的我不选择从图书馆的形象,我只是拍照,并用它来放过来的其他图像,这对我的作品完美。

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
    }
}


文章来源: Not able to show the Image in proper format from camera in landscape mode