2010-09-01 22 views

risposta

17

utilizzare il blocco. qualcosa di simile:

[[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

Ecco la salsa, grazie! – Shizam

+0

Come fai a sapere quando è ok chiamare di nuovo captureStillImageAsynchronouslyFromConnection? – Shizam

+0

Nevermind, capito :) – Shizam