Created
March 27, 2013 13:23
-
-
Save soulfly/5254116 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void) captureStillImage | |
{ | |
AVCaptureConnection *stillImageConnection = [AVCamUtilities connectionWithMediaType:AVMediaTypeVideo fromConnections:[[self stillImageOutput] connections]]; | |
if ([stillImageConnection isVideoOrientationSupported]) | |
[stillImageConnection setVideoOrientation:orientation]; | |
[[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:stillImageConnection | |
completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) { | |
ALAssetsLibraryWriteImageCompletionBlock completionBlock = ^(NSURL *assetURL, NSError *error) { | |
if (error) { | |
if ([[self delegate] respondsToSelector:@selector(captureManager:didFailWithError:)]) { | |
[[self delegate] captureManager:self didFailWithError:error]; | |
} | |
} | |
}; | |
if (imageDataSampleBuffer != NULL) { | |
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer]; | |
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; | |
UIImage *image = [[UIImage alloc] initWithData:imageData]; | |
[library writeImageToSavedPhotosAlbum:[image CGImage] | |
orientation:(ALAssetOrientation)[image imageOrientation] | |
completionBlock:completionBlock]; | |
[image release]; | |
[library release]; | |
} | |
else | |
completionBlock(nil, error); | |
if ([[self delegate] respondsToSelector:@selector(captureManagerStillImageCaptured:)]) { | |
[[self delegate] captureManagerStillImageCaptured:self]; | |
} | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment