jpegStillImageNSDataRepresentation 不尊重镜像?

发布于 2024-12-12 02:58:23 字数 1350 浏览 0 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文