iPhone kameradan kareleri yakalayan ve bu karelerle bazı işlemleri gerçekleştiren bir uygulama oluşturmaya çalışıyorum. İnternette bulunan bazı kodları denedim, ör. Burada: How to capture image without displaying preview in iOSNeden AVCaptureStillImageOutput :: captureStillImageAsynchronouslyFromConnection: completionHandler hiç çağrılmadı mı?
ve ben aşağıdaki kod parçası ile sona erdi:
-(IBAction)captureNow{
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)
{
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];
// do the processing with the image
}
Ancak, uygulama asla yüzden çerçeveden görüntüyü asla captureStillImageAsynchronouslyFromConnection yönteminin işleyicisi kod bloğunun içine alır. Yanlış bir şekilde bir şey yapıyorum? Önerileriniz için teşekkürler!
“AVCaptureSession” ın hala çalışıyor olup olmadığını kontrol edebilirsiniz. Eğer bunu erken bitirirseniz, tamamladığınızHandler asla aranmaz. –