从Front Camera iOS 5.0捕获时始终看到镜像

时间:2012-02-10 12:03:34

标签: iphone ios ipad ios5

从前置摄像头捕获数据时,我总是得到镜像,如何在预览窗口中看到我所看到的内容。我已将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返回成功)

3 个答案:

答案 0 :(得分:9)

使用以下代码翻转镜像图像。

UIImage * flippedImage = [UIImage imageWithCGImage:picture.CGImage scale:picture.scale orientation:UIImageOrientationLeftMirrored];

答案 1 :(得分:2)

Swift版本:

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

答案 2 :(得分:0)

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

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