2010-09-01 7 views
7

कैसे कर आप सेटअप के लिए पूरा होने हैंडलर:आप AVCaptureStillImageOutput का उपयोग कैसे करते हैं, विशेष रूप से captureStillImageAsynchronouslyFromConnection?

captureStillImageAsynchronouslyFromConnection: completionHandler:

AVCaptureStillImageOutput के लिए

?

  • (शून्य) कैप्चर डिलीगेट: (CMSampleBufferRef) बफर त्रुटि: (NSError *) त्रुटि;

?

उत्तर

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]; 
                  } 
                 } 
                }]; 
+0

सॉस, धन्यवाद! – Shizam

+0

कैप्चर करने के लिए ठीक है जब आप कैसे जानते हैं StillImageAsynchronouslyFromConnection फिर से? – Shizam

+0

कभी नहीं, इसे समझ लिया :) – Shizam

संबंधित मुद्दे