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