Warum funktioniert die Aufnahme von Bildern mit AVFoundation mir 480x640 Bilder, wenn die voreingestellten 640x480 ist?

Habe ich einige ziemlich basic-code, um ein Standbild mit 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];

Meine Methode erfasst das Standbild ist auch Recht einfach und druckt die Ausrichtung, die 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);

                                                         }];
}

Damit das Gerät versteht es im portrait-Modus, wie es sein sollte, die exif-Geräten zeigen mir:

PixelXDimension = 640;
PixelYDimension = 480;

so scheint es, zu wissen, dass wir in 640x480 und das bedeutet, dass BxH (offensichtlich...)

Allerdings, wenn ich E-Mail das Foto, um mich von Apples Fotos-app, bekomme ich eine 480x640 Bild, wenn ich überprüfen Sie die Eigenschaften in der Vorschau. Dies machte keinen Sinn für mich, bis ich grub weiter in den Bild-Eigenschaften zu erfahren, dass die Bild-Ausrichtung ist "6 (um 90 ° Gedreht CCW)" ich bin sicher, CCW gegen den Uhrzeigersinn

So sah das Bild im browser:
http://tonyamoyal.com/stuff/things_that_make_you_go_hmm/photo.JPG
Sehen wir das Bild um 90 ° gedreht CCW und es ist 640x480.

Ich bin wirklich verwirrt über dieses Verhalten. Wenn ich eine 640x480 Standbild mit AVFoundation, würde ich erwarten, dass der Standard keine Drehung. Ich erwarte ein Bild der Größe 640x480 orientiert, genau wie mein Auge sieht das Bild in der Vorschau-Ebene. Kann jemand erklären, warum dies geschieht und wie die Konfiguration der Erfassung, so dass, wenn ich speichern mein Bild an den server, um später die Anzeige in einem web-Ansicht, es ist nicht um 90 ° gedreht CCW?

InformationsquelleAutor Tony | 2011-08-07
Schreibe einen Kommentar