jpegStillImageNSDataRepresentation 不尊重镜像?
我正在使用 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];
}
}];
}
I'm using jpegStillImageNSDataRepresentation to capture a still image from the front-facing camera on an iOS device (iOS 5.0).
I'm using a AVCaptureVideoPreviewLayer to display the output of the front-facing camera prior to taking the image. By default, the display is mirrored, and I do not adjust this.
The still image that is captured is not mirrored (i.e. it is flipped about the vertical axis compared with what is displayed by the preview layer). I want it to be mirrored. Any ideas how to accomplish that?
Here is the relevant code:
- (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];
}
}];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论