मैं एक ऐप बनाने की कोशिश करता हूं जो आईफोन कैमरे से फ्रेम को कैप्चर करता है और इन फ्रेमों के साथ कुछ प्रोसेसिंग करता है। मैंने इंटरनेट पर पाए गए कोड के कुछ टुकड़े करने की कोशिश की, उदा। यहाँ: How to capture image without displaying preview in iOSक्यों AVCaptureStillImageOutput :: captureStillImageAsynchronouslyFromConnection: completHandler कभी नहीं कहा जाता है?
और मैं कोड का निम्न भाग के साथ समाप्त हो गया:
-(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
}
हालांकि, एप्लिकेशन कभी नहीं captureStillImageAsynchronouslyFromConnection विधि का हैंडलर कोड ब्लॉक में हो जाता है तो मैं कभी नहीं फ्रेम से छवि मिलता है। क्या मैं गलत तरीके से कुछ कर रहा हूं? आपके सुझावों के लिए धन्यवाद!
आप जांच सकते हैं कि आपका 'AVCaptureSession' अभी भी चल रहा है या नहीं। यदि आप इसे जल्दी खत्म करते हैं, तो आपका पूरा होने वाला हैंडलर कभी नहीं बुलाया जाता है। –