【发布时间】:2012-01-03 16:41:01
【问题描述】:
我想使用 AVFoundation 框架实现连拍模式(快速连续 5 次拍摄),但遇到了困难。
for(int imgNum = 0; imgNum < nImages; imgNum++)
{
float dT = imgNum*4.0 - (CFAbsoluteTimeGetCurrent() - startTime);
NSLog(@"Waiting for %.02f seconds...\n",dT);
[NSThread sleepForTimeInterval:dT];
[self takeStill:videoConnection];
}
- takeStill:(AVCaptureConnection*)videoConnection
{
[stillOut captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler:^(CMSampleBufferRef imageSampleBuffer, NSError *error)
{
if(error)
NSLog(@"%s",[[error localizedDescription] UTF8String]);
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
// {...} Save as a png
}];
}
以这种方式拍摄一张图像效果很好。看起来,休眠线程会导致完成处理程序永远不会触发,直到所有nImages 都被占用,结果是imageSampleBuffer 为NULL。处理这个问题的正确方法是什么?
【问题讨论】:
标签: iphone avfoundation