转载:http://blog.csdn.net/enjolras1024/article/details/73471565
初始化图片输入和输出源(AVCaptureDeviceInput,AVCaptureStillImageOutput)
self.deviceInput = [[AVCaptureDeviceInput alloc] initWithDevice:self.device error:&error];
self.imageOutput = [[AVCaptureStillImageOutput alloc] init];
NSDictionary *outputSetting = [[NSDictionary alloc] initWithObjectsAndKeys:AVVideoCodecKey, AVVideoCodecJPEG, nil];
[self.imageOutput setOutputSettings:outputSetting];
if ([self.session canAddInput:self.deviceInput]) {
[self.session addInput:self.deviceInput];
}
if ([self.session canAddOutput:self.imageOutput]) {
[self.session addOutput:self.imageOutput];
}
设置前置摄像头拍照不镜像
// 设置前置摄像头拍照不镜像
AVCaptureDevicePosition currentPosition=[[self.deviceInput device] position];
AVCaptureConnection *connection = [self.imageOutput connectionWithMediaType:AVMediaTypeVideo];
if (currentPosition == AVCaptureDevicePositionUnspecified || currentPosition == AVCaptureDevicePositionFront) {
connection.videoMirrored = YES;
} else {
connection.videoMirrored = NO;
}