草庐IT

IOS swift 3 : Flip Front Camera Image Horizontally after taking Camera Picture

coder 2023-07-15 原文

StackOverflow 上有几个处理图像翻转的问题,例如这个 here .默认情况下,iOS 会在拍摄照片时反转前置摄像头的水平图像。我试图防止前置摄像头图像仅被翻转或将其翻转回正确的方向。我正在与 WKWebview 进行交互。

问题是我不知道调用什么方法或在我的 ViewController 中放置什么方法来获取相机,然后将其设置为正确的方向,或者正确的设置来防止这种行为。我也不知道如何获取拍摄图像的相机信息。

这是我尝试的一种解决方案,它基于翻译一些 Objective-C 代码以在相机处理完照片后更改图像。然而,图片变量是一个常量,无法更改:

func didTakePicture(_ picture: UIImage) {
    var flippedImage = UIImage(cgImage: picture.cgImage!, scale: picture.scale, orientation: .leftMirrored)
    picture = flippedImage
}

如有任何帮助,我们将不胜感激。谢谢!

最佳答案

您正在正确地翻转图像,但为什么要将翻转后的图像分配回 picture 变量,您可以使用 flippedImage 变量并将其传递到需要的地方。

func didTakePicture(_ picture: UIImage) {
    var flippedImage = UIImage(CGImage: picture.CGImage!, scale: picture.scale, orientation: .leftMirrored)
    // Here you have got flipped image you can pass it wherever you are using image
}

What I am trying to do is prevent the front camera image only from being flipped

如果您使用的是默认相机,则无法阻止相机防止翻转图像。为此,您需要使用 AVFoundation 创建自己的相机,并需要在那里应用您的逻辑。

如果您准备好使用任何第三方库,那么您可以查看 LEMirroredImagePicker

关于IOS swift 3 : Flip Front Camera Image Horizontally after taking Camera Picture,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40665671/

有关IOS swift 3 : Flip Front Camera Image Horizontally after taking Camera Picture的更多相关文章

随机推荐