Ich versuche das neue AVFoundation framework
für die Aufnahme von Standbildern mit dem iPhone zu verwenden.iPhone SDK 4 AVFoundation - Wie benutze CaptureStillImageAsynchronousFromConnection korrekt?
Mit einem Tastendruck wird dieses Verfahren aufgerufen. Ich kann den Auslöser hören, aber ich kann die Protokollausgabe nicht sehen. Wenn ich diese Methode mehrmals anrufe, wird die Kameravorschau eingefroren.
Gibt es eine Anleitung, wie Sie captureStillImageAsynchronouslyFromConnection
verwenden können?
[[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:
[[self stillImageOutput].connections objectAtIndex:0]
completionHandler:^(CMSampleBufferRef imageDataSampleBuffer,
NSError *error) {
NSLog(@"inside");
}];
- (void)initCapture { AVCaptureDeviceInput *captureInput = [AVCaptureDeviceInput deviceInputWithDevice:[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo] error:nil]; AVCaptureVideoDataOutput *captureOutput = [[AVCaptureVideoDataOutput alloc] init]; captureOutput.alwaysDiscardsLateVideoFrames = YES; dispatch_queue_t queue; queue = dispatch_queue_create("cameraQueue", NULL); [captureOutput setSampleBufferDelegate:self queue:queue]; dispatch_release(queue); NSString* key = (NSString*)kCVPixelBufferPixelFormatTypeKey; NSNumber* value = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA]; NSDictionary* videoSettings = [NSDictionary dictionaryWithObject:value forKey:key]; [captureOutput setVideoSettings:videoSettings]; self.captureSession = [[AVCaptureSession alloc] init]; self.captureSession.sessionPreset = AVCaptureSessionPresetLow; [self.captureSession addInput:captureInput]; [self.captureSession addOutput:captureOutput]; self.prevLayer = [AVCaptureVideoPreviewLayer layerWithSession: self.captureSession]; [self.prevLayer setOrientation:AVCaptureVideoOrientationLandscapeLeft]; self.prevLayer.frame = CGRectMake(0.0, 0.0, 480.0, 320.0); self.prevLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; [self.view.layer addSublayer: self.prevLayer]; // Setup the default file outputs AVCaptureStillImageOutput *_stillImageOutput = [[[AVCaptureStillImageOutput alloc] init] autorelease]; NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys: AVVideoCodecJPEG, AVVideoCodecKey, nil]; [_stillImageOutput setOutputSettings:outputSettings]; [outputSettings release]; [self setStillImageOutput:_stillImageOutput]; if ([self.captureSession canAddOutput:stillImageOutput]) { [self.captureSession addOutput:stillImageOutput]; } [self.captureSession commitConfiguration]; [self.captureSession startRunning]; }
Ich weiß nicht, ob das im Jahr 2010 wahr war, aber seit Ende 2011, ich habe einfach 'captureStillImageAsynchronousFromConnection' bei der Gleichzeitig mit dem Erhalt eines Video-Feeds mit dem Delegate von AVCaptureVideoDataOutput, "captureOutput" und während der Verwendung eines previewLayers. Ich bekomme ein 5megapixel Bild von stillImage, ein 852x640 für den Video Feed und previewLayer. – mahboudz
Der obige Kommentar basiert auf einem iPhone4. Auf einem iPhone 4s bekomme ich noch eine 8megapixel, während ich für den Videofeed und previewLayer 852x640 bekomme. – mahboudz
Was ist der Unterschied zwischen initWithSession und layerWithSession? Die Dokumente diskutieren nicht, wann man das eine gegen das andere verwendet. http://developer.apple.com/library/ios/#documentation/AVFoundation/Reference/AVCaptureVideoPreviewLayer_Class/Reference/Reference.html – knite