如何为:
设置完成处理程序captureStillImageAsynchronouslyFromConnection:completionHandler:
for AVCaptureStillImageOutput?
答案 0 :(得分:17)
使用块。 像这样的东西:
[[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:videoConnection
completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
if (imageDataSampleBuffer != NULL) {
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
UIImage *image = [[UIImage alloc] initWithData:imageData];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeImageToSavedPhotosAlbum:[image CGImage]
orientation:(ALAssetOrientation)[image imageOrientation]
completionBlock:^(NSURL *assetURL, NSError *error){
if (error) {
id delegate = [self delegate];
if ([delegate respondsToSelector:@selector(captureStillImageFailedWithError:)]) {
[delegate captureStillImageFailedWithError:error];
}
}
}];
[library release];
[image release];
} else if (error) {
id delegate = [self delegate];
if ([delegate respondsToSelector:@selector(captureStillImageFailedWithError:)]) {
[delegate captureStillImageFailedWithError:error];
}
}
}];