AVCaptureVideoOrientation Querformat Ergebnis in upside-down-Standbilder

Im mit AVCaptureSession für die Aufnahme von Bildern und speichern von Bildern zum album. Wenn ich auf die Schaltfläche klicke, nimmt es den snapshot und speichern album. Aber wenn ich landscape-Modus, klicken Sie dann auf die Schaltfläche speichert Querformat Ergebnis in upside-down-Standbilder.

AVCaptureVideoOrientation Querformat Ergebnis in upside-down-Standbilder

code:

- (void)viewDidLoad
{
    [super viewDidLoad];
    //Do any additional setup after loading the view.

    [self setCaptureSession:[[AVCaptureSession alloc] init]];


    [self  addVideoInputFrontCamera:NO]; //set to YES for Front Camera, No for Back camera

    [self  addStillImageOutput];

    [self setPreviewLayer:[[AVCaptureVideoPreviewLayer alloc] initWithSession:[self captureSession]] ];

      [[self previewLayer] setVideoGravity:AVLayerVideoGravityResizeAspectFill];

      CGRect layerRect = [[[self view] layer] bounds];


    [[self previewLayer]setBounds:layerRect];
    [[self  previewLayer] setPosition:CGPointMake(CGRectGetMidX(layerRect),CGRectGetMidY(layerRect))];
    [[[self view] layer] addSublayer:[self  previewLayer]];

     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveImageToPhotoAlbum) name:kImageCapturedSuccessfully object:nil];


    [[self captureSession] startRunning];

camera=[UIButton buttonWithType:UIButtonTypeCustom];
[camera setImage:[UIImage imageNamed:@"button.png"] forState:UIControlStateNormal];
[camera setFrame:CGRectMake(150, 10, 40, 30)];
[camera addTarget:self action:@selector(takephoto:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:camera];

}

Taste für die Aufnahme von Bild:

-(void)takephoto:(id)sender{

[self captureStillImage];

}

- (void)captureStillImage
{
    AVCaptureConnection *videoConnection = nil;
    for (AVCaptureConnection *connection in [[self 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: %@", [self stillImageOutput]);

    [[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:videoConnection
                                                         completionHandler:^(CMSampleBufferRef imageSampleBuffer, NSError *error) {
                                                             CFDictionaryRef exifAttachments = CMGetAttachment(imageSampleBuffer, kCGImagePropertyExifDictionary, NULL);
                                                             if (exifAttachments) {
                                                                 NSLog(@"attachements: %@", exifAttachments);
                                                             } else {
                                                                 NSLog(@"no attachments");
                                                             }

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


                                                            [self setStillImage:image];



                                                             // [image release];
                                                             [[NSNotificationCenter defaultCenter] postNotificationName:kImageCapturedSuccessfully object:nil];

                                                         }];


}
  • Ich schlage vor, Sie Lesen: Warum AVCaptureVideoOrientation Querformat Ergebnis in upside-down-Standbilder?
  • Ich sah schon, dass. Aber ich habe nicht Ahnung, wie zu tun?
  • Ich werde offline sein, alle Tag, aber wenn u haben keine nützlichen Antworten bis heute Abend gebe ich u mehr Details
  • Im portrait-Modus funktioniert. Im landscape-Modus funktioniert es nicht. Einige docs sagt, nur die Verwendung im hoch-oder Querformat. Aber ich muss an beiden Modus
  • Ich habe nicht um Antwort
  • leider dauerte es eine Weile, ich war beschäftigt. Ich habe gerade gebucht eine Antwort. Für eine gute standard-code-Beispiel von Apple, nehmen Sie einen Blick an SquareCam.

InformationsquelleAutor user2474320 | 2013-07-25
Schreibe einen Kommentar