使用AVFoundation自定义相机,调用后置摄像头没问题,但是调用前置摄像头却左右成像问题:
UIImageOrientation imgOrientation; //拍摄后获取的的图像方向
if ([self.device.localizedName isEqualToString:@"背面相机"]) {
// 后置摄像头图像方向 UIImageOrientationRight
imgOrientation = UIImageOrientationRight;
NSLog(@"后置摄像头");
} else {
// 前置摄像头图像方向 UIImageOrientationLeftMirrored
// IOS前置摄像头左右成像
imgOrientation = UIImageOrientationLeftMirrored;
NSLog(@"前置摄像头");
}
//获取拍摄图片
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
UIImage *t_image = [UIImage imageWithData:imageData];
UIImage *image = [[UIImage alloc]initWithCGImage:t_image.CGImage scale:1.0f orientation:imgOrientation];
self.image = image;
[image release];