iOS 5.0前置摄像头拍照时总是出现镜像图像

10

从前置摄像头获取数据时,我总是得到镜像图像,如何获得与预览窗口中看到的相同的图像。我已将 videoMirrored 设置为 TRUE。以下是代码片段:

AVCaptureConnection *lConnection = nil;

  for ( AVCaptureConnection *connection in [lHandle->m_output connections]) {
     for ( AVCaptureInputPort *port in [connection inputPorts] ) {
         if ( [[port mediaType] isEqual:AVMediaTypeVideo] ) {
             lConnection = connection;
             break;
         }
     }
 }
if ([lConnection isVideoOrientationSupported])
    [lConnection setVideoOrientation:AVCaptureVideoOrientationPortrait];
if ([lConnection isVideoMirroringSupported])
    [lConnection setVideoMirrored:TRUE];

setVideoMirrored 更改为 True/False 也不会改变任何内容(isVideoMirroringSupported 返回成功)


1
我非常确定你的预览窗口应该显示镜像视频(也就是说,好像你在照镜子一样,举起右手,显示器右侧的手臂也会上升)——当你捕获数据时,它是否在这个意义上是镜像的,还是相对于你的预览窗口是镜像的(因此,从传感器中获取的内容是正确的)? - Tommy
1
谢谢Tommy。你能告诉我为什么将SetVideoMirrored设置为TRUE/FALSE没有改变任何东西吗? - Rajat Kothari
谢谢@Tommy。你能告诉我为什么将SetVideoMirrored设置为TRUE/FALSE没有改变任何东西吗? - Rajat Kothari
如果我可以的话,我会回答你的问题!我假设你已经检查过 supportsVideoMirroring 是否确实返回了 YES? - Tommy
1
@Tommy。是的,我已经检查了isVideoMirroringSupported是否返回YES,并尝试将setVideoMirrored设置为YES / NO。但我没有看到任何变化。 - Rajat Kothari
1
@RajatKothari,你最终找到了解决这个问题的方法吗?我也遇到了前置摄像头的同样问题。 - Sadjad
3个回答

9
使用以下代码翻转镜像图像。
UIImage * flippedImage = [UIImage imageWithCGImage:picture.CGImage scale:picture.scale orientation:UIImageOrientationLeftMirrored];

1
如果你横向拍摄照片,这将不起作用。 - John Rogers

3

Swift版本:

let flippedImage = UIImage(CGImage: image.CGImage, scale: image.scale, orientation: .LeftMirrored)

0

您可以使用 withHorizontallyFlippedOrientation() 来翻转 UIImage。

// first get an UIImage from the front camera
let sourceImg = UIImage(cgImage: image, scale: 1.0, orientation: .leftMirrored)
return sourceImg.withHorizontallyFlippedOrientation()

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接