How to Fix capturing images with front facing camera mirrors image, AVFoundation,Swift

前端 未结 2 950
情歌与酒
情歌与酒 2021-01-06 05:21

How to Fix capturing images with front facing camera mirrors image? SnapChat seems to fix it as well as WhatsApp and Instagram , how can i? i would really love to find a sol

相关标签:
2条回答
  • 2021-01-06 05:47

    I did that a long ago. I don't have my system with me but i can say that transform your preview layer horizontally and it will show exact result as you want. For saving and exporting you will find lot of examples out here.

    0 讨论(0)
  • 2021-01-06 06:05

    i figured this out myself, Here is the solution:

    if captureDevice.position == AVCaptureDevicePosition.back {
                if let image = context.createCGImage(ciImage, from: imageRect) {
                    return UIImage(cgImage: image, scale: UIScreen.main.scale, orientation: .right)
                    }
                }
    
                    if captureDevice.position == AVCaptureDevicePosition.front {
                        if let image = context.createCGImage(ciImage, from: imageRect) {
                        return UIImage(cgImage: image, scale: UIScreen.main.scale, orientation: .leftMirrored)
    
            }
        }
            }
            return nil
            }
    
    0 讨论(0)
提交回复
热议问题