Как вы используете AVCaptureStillImageOutput, в частности captureStillImageAsynchronouslyFromConnection? - PullRequest
7 голосов
/ 02 сентября 2010

Как настроить обработчик завершения для:

captureStillImageAsynchronouslyFromConnection: завершению: завершение:

для AVCaptureStillImageOutput?

  • (void) captureDelegate: (CMSampleBufferefefef): (NSError *) ошибка;

?

1 Ответ

17 голосов
/ 03 сентября 2010

использовать блок.как то так:

[[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];
                                                             }
                                                         }
                                                     }];
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...