Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you use AVCaptureStillImageOutput, captureStillImageAsynchronouslyFromConnection in particular?

How do you setup the completion handler for:

captureStillImageAsynchronouslyFromConnection:completionHandler:

for AVCaptureStillImageOutput?

  • (void)captureDelegate:(CMSampleBufferRef)buffer error:(NSError *)error;

?

like image 229
Shizam Avatar asked Sep 01 '10 22:09

Shizam


1 Answers

use block. something like this:

[[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];
                                                             }
                                                         }
                                                     }];
like image 159
Nico Prananta Avatar answered Nov 07 '22 08:11

Nico Prananta