Created
August 12, 2012 02:46
-
-
Save dhilipsiva/3329218 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)viewDidLoad { | |
[super viewDidLoad]; | |
[self setSession:[[AVCaptureSession alloc] init]]; | |
[_session setSessionPreset:AVCaptureSessionPresetHigh]; | |
[self setViewLayer:self.vPreview.layer]; | |
[self setCaptureVideoPreviewLayer:[[AVCaptureVideoPreviewLayer alloc] initWithSession:_session]]; | |
[_captureVideoPreviewLayer setFrame:[_vPreview bounds]]; | |
if ([_captureVideoPreviewLayer isOrientationSupported]) { | |
[_captureVideoPreviewLayer setOrientation:AVCaptureVideoOrientationPortrait]; | |
} | |
[_captureVideoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill]; | |
[_vPreview.layer addSublayer:_captureVideoPreviewLayer]; | |
[self setDevice:[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]]; | |
NSError *error = nil; | |
[self setInput:[AVCaptureDeviceInput deviceInputWithDevice:_device error:&error]]; | |
if (!_input) { | |
NSLog(@"ERROR: trying to open camera: %@", error); | |
} | |
[_session addInput:_input]; | |
[self setStillImageOutput:[[AVCaptureStillImageOutput alloc] init]]; | |
NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys: AVVideoCodecJPEG, AVVideoCodecKey, nil]; | |
[_stillImageOutput setOutputSettings:outputSettings]; | |
[_session addOutput:_stillImageOutput]; | |
[_session startRunning]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment