我正在使用jpegStillImageNSDataRepresentation从iOS设备(iOS 5.0)上的前置摄像头捕获静止图像。
我正在使用AVCaptureVideoPreviewLayer在拍摄图像之前显示前置摄像头的输出。默认情况下,显示器是镜像的,我不会调整它。
捕获的静止图像不镜像(即,与预览图层显示的内容相比,它围绕垂直轴翻转)。我希望它被镜像。任何想法如何实现?
以下是相关代码:
- (void) captureStillImage {
AVCaptureConnection *stillImageConnection = [stillImageOutput connectionWithMediaType:AVMediaTypeVideo];
UIDeviceOrientation curDeviceOrientation = [[UIDevice currentDevice] orientation];
AVCaptureVideoOrientation avcaptureOrientation = [self avOrientationForDeviceOrientation:curDeviceOrientation];
[stillImageConnection setVideoOrientation:avcaptureOrientation];
[stillImageOutput setOutputSettings:[NSDictionary dictionaryWithObject:AVVideoCodecJPEG
forKey:AVVideoCodecKey]];
[stillImageOutput captureStillImageAsynchronouslyFromConnection:stillImageConnection completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
if (!error) {
NSData *jpegData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
UIImage *image = [UIImage imageWithData:jpegData];
[self showImage:image];
}
}];
}