Почему при захвате изображений с помощью AVFoundation я получаю изображения 480x640, когда по умолчанию установлено 640x480?

У меня есть довольно простой код для захвата неподвижного изображения с помощью AVFoundation.

AVCaptureDeviceInput *newVideoInput = [[AVCaptureDeviceInput alloc] initWithDevice:[self backFacingCamera] error:nil];

    AVCaptureStillImageOutput *newStillImageOutput = [[AVCaptureStillImageOutput alloc] init];

    NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys:
                                    AVVideoCodecJPEG, AVVideoCodecKey,
                                    nil];


    [newStillImageOutput setOutputSettings:outputSettings];
    [outputSettings release];


    AVCaptureSession *newCaptureSession = [[AVCaptureSession alloc] init];
    [newCaptureSession beginConfiguration];
    newCaptureSession.sessionPreset = AVCaptureSessionPreset640x480;

    [newCaptureSession commitConfiguration];
    if ([newCaptureSession canAddInput:newVideoInput]) {
        [newCaptureSession addInput:newVideoInput];
    }
    if ([newCaptureSession canAddOutput:newStillImageOutput]) {
        [newCaptureSession addOutput:newStillImageOutput];
    }
    self.stillImageOutput = newStillImageOutput;
    self.videoInput = newVideoInput;
    self.captureSession = newCaptureSession;

    [newStillImageOutput release];
    [newVideoInput release];
    [newCaptureSession release];

Мой метод захвата неподвижного изображения также довольно прост и распечатывает ориентацию, которая является AVCaptureVideoOrientationPortrait:

- (void) captureStillImage
{
    AVCaptureConnection *stillImageConnection = [AVCamUtilities connectionWithMediaType:AVMediaTypeVideo fromConnections:[[self stillImageOutput] connections]];

    if ([stillImageConnection isVideoOrientationSupported]){
        NSLog(@"isVideoOrientationSupported - orientation = %d", orientation);
        [stillImageConnection setVideoOrientation:orientation];
    }

    [[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:stillImageConnection
                                                         completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {


                                                             ALAssetsLibraryWriteImageCompletionBlock completionBlock = ^(NSURL *assetURL, NSError *error) {
                                                                 if (error) { // HANDLE }
                                                             };

                                                                 if (imageDataSampleBuffer != NULL) {

                                                                 CFDictionaryRef exifAttachments = CMGetAttachment(imageDataSampleBuffer, kCGImagePropertyExifDictionary, NULL);
                                                                 if (exifAttachments) {
                                                                     NSLog(@"attachements: %@", exifAttachments);
                                                                 } else { 
                                                                     NSLog(@"no attachments");
                                                                 }
                                                                 self.stillImageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];                                                                  
                                                                 self.stillImage = [UIImage imageWithData:self.stillImageData];

                                                                 UIImageWriteToSavedPhotosAlbum(self.stillImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
                                                     }
                                                             else
                                                                 completionBlock(nil, error);

                                                         }];
}

Итак, устройство понимает, что это портретный режим, как и должно быть, приложения exif показывают мне:

PixelXDimension = 640;
PixelYDimension = 480;

так что это похоже, знает, что у нас разрешение 640x480, а это означает WxH (очевидно ...)

Однако, когда я отправляю фотографию себе по электронной почте из приложения Apple Photos, я получаю изображение 480x640, если проверяю свойства в Preview. Для меня это не имело никакого смысла, пока я не углубился в свойства изображения и не обнаружил, что ориентация изображения установлена ​​на «6 (повернут на 90 градусов против часовой стрелки)». Я уверен, что против часовой стрелки идет против часовой стрелки

. изображение в браузере: http://tonyamoyal.com/stuff/things_that_make_you_go_hmm/photo.JPG Мы видим изображение, повернутое на 90 градусов против часовой стрелки, и его размер 640x480.

Я действительно сбит с толку этим поведением. Когда я беру неподвижное изображение 640x480 с помощью AVFoundation, я ожидал, что по умолчанию не будет повернутой ориентации. Я ожидаю, что изображение 640x480 будет ориентировано точно так, как мой глаз видит изображение в слое предварительного просмотра. Может ли кто-нибудь объяснить, почему это происходит и как настроить захват, чтобы при сохранении изображения на сервере для последующего отображения в веб-представлении оно не поворачивалось на 90 градусов против часовой стрелки?

8
задан Tony 7 August 2011 в 11:35
поделиться