无法以横向模式从相机以适当的格式显示图像

我正在使用Ios6的iPad应用程序,当我们点击正确的酒吧button,我正在做一个如下的行动:

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

我的问题是,当我在土地景观模式,如果我点击button。 每次使用后,相机将以纵向模式显示(图像以反向模式显示)。 但是,如果我摇动iPad然后它显示在LandScape即正确的方向。

看到下面的图片

当我在景观模式,如果我点击button相机显示图像如下:

在这里输入图像说明

如果我摇动iPad然后相机显示如下图像:

在这里输入图像说明

我尝试了很多,并search了一下,但是我没有find任何解决scheme。 这是我的时间,所以如果任何人已经在这个工作,请指导我,并张贴示例代码。

你可以尝试给你的imagePickerController转换

 imagePickerController.view.transform = CGAffineTransformMakeRotation(-M_PI/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; } 

我在Googlesearch中研究你的问题,得到如下结果或可能性:

结果1

一些答案说,它的iOS 6的错误,所以你不能修复它像波纹pipe队列: –

iPad相机popover预览错误的旋转和缩放

结果2

我不认为我们可以控制摄像机的方向。摄像机的方向属性是内置的,随着设备的方向而变化。

iPad相机定位肖像模式?

结果3

您可以在中心pipe理缩放的实时iPhone摄像头视图物理移动选取框。 由贝娄代码: –

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

希望你有实际的解决scheme。 关于这个错误或问题

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

你有没有尝试过创buildUIImagePickerController的子类,并从ViewController(这是超类)实现interfaceOrientation的方法?

请试试这个

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

我有一个iPad应用程序只有lanscape模式,我吓坏了,因为我阅读所有这些post,但我用这个非常简单的代码来拍照,它适用于我唯一的lanscape应用程序完美。 重要的是,我不会从图书馆中select一张图片,只是把图片拿来放在另一张图片上,这对我来说是完美的。

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