我正在简化AVCamDemo
项目,以便我可以尝试仅捕获静止图像。
下面是captureStillImage()
方法的新代码:
- (void) captureStillImage
{
AVCaptureConnection *stillImageConnection = [AVCamUtilities connectionWithMediaType:AVMediaTypeVideo fromConnections:[[self stillImageOutput] connections]];
if ([stillImageConnection isVideoOrientationSupported]) {
[stillImageConnection setVideoOrientation:orientation];
}
[[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:stillImageConnection
completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
NSLog(@"In the completionHandler block");
if (imageDataSampleBuffer != NULL) {
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
UIImage *image = [[UIImage alloc] initWithData:imageData];
[self writeImageFile:image];
[image release];
}
if ([[self delegate] respondsToSelector:@selector(captureManagerStillImageCaptured:)]) {
[[self delegate] captureManagerStillImageCaptured:self];
}
}];
NSLog(@"exiting....");
}
在我的测试中,我发现有时,块中的 NSLog 语句没有被执行......因此 stillImage文件没有得到保存。
我遇到时间问题了吗?如果是这样,我该如何解决它们?
谢谢并恭祝安康。山姆。