2

我正在使用 AVFoundation 在 UIViewController 的纵向摄像头视图中使用前置摄像头以编程方式捕获静止图像。这一切都很好。

我遇到的问题是,当我通过动画在 UIImageView 内显示我在当前会话中拍摄的图片时,所有图片都显示为横向左侧,我需要以它们拍摄的方向显示图片,即纵向。

我曾尝试强制设备/图像方向为纵向,但没有任何运气。

如果有人能告诉我哪里出错了,那就太好了。谢谢

我在下面包含了我的代码片段。

//拍照并将拍摄的图像存储到可变数组

-(无效)拍照{

AVCaptureConnection *videoConnection = nil;
for (AVCaptureConnection *connection in stillImageOutput.connections)
{
    for (AVCaptureInputPort *port in [connection inputPorts])
    {
        if ([[port mediaType] isEqual:AVMediaTypeVideo] )
        {
            videoConnection = connection;
            break;
        }
    }
    if (videoConnection) { break; }
}

NSLog(@"about to request a capture from: %@", stillImageOutput);  
[stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error)
 {
     if ([videoConnection isVideoOrientationSupported])
         [videoConnection setVideoOrientation:[UIDevice currentDevice].orientation];

     CFDictionaryRef exifAttachments = CMGetAttachment( imageSampleBuffer, kCGImagePropertyExifDictionary, NULL);
     if (exifAttachments)
     {
         // Do something with the attachments.
         NSLog(@"attachements: %@", exifAttachments);
     }
     else
         NSLog(@"no attachments");

     NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
     UIImage *image = [[UIImage alloc] initWithData:imageData];

     UIImage *orientedImage= [[UIImage alloc] initWithCGImage: image.CGImage scale:1.0 orientation:UIImageOrientationUp];
     NSLog(@"the image oreintation is %i", orientedImage.imageOrientation);

     [photosTakenArray addObject:orientedImage];

...

这就是我使用 UIImageView startAnimating 函数显示相机在另一个 UIViewController 中拍摄的图像的方式。这就是相机拍摄的照片都以横向显示的问题所在。在这种情况下,photoViewer 是我的 UIImageView,photosToShow 是对上面 photosTakenArray 的 NSArray 引用。

if ([photosToShow count]>0) {

    NSLog(@"we have %i photos to display", [photosToShow count]);
    photoViewer.animationImages = photosToShow;

    // all frames will execute in 1.75 seconds
    photoViewer.animationDuration = 1.75;
    // repeat the annimation forever
    photoViewer.animationRepeatCount = 0;
    // start animating
    [photoViewer startAnimating];

...

4

1 回答 1

0

我也遇到了同样的问题然后我改变了我的代码delegate imagePickerController

-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
{
    //NSLog(@"%@",info);

    dataImage = UIImageJPEGRepresentation([info objectForKey:@"UIImagePickerControllerOriginalImage"],1);
 }  

希望对你有帮助

于 2012-12-12T07:33:59.893 回答