在StackOverflow上有几个问题涉及图像翻转,例如此处的问题。默认情况下,iOS在拍摄照片时反转前置摄像头的水平图像。我试图防止仅将前置摄像头图像翻转或将其翻转回正确的方向。我正在与互动WKWebview
。
问题是我不知道要调用哪种方法或将其放入ViewController
相机中,然后将其设置为正确的方向或正确的设置来防止这种行为。我也不知道如何获取拍摄图像的相机信息。
这是我尝试的一种解决方案,该解决方案是基于在翻译完成相机后的一些Objective-C代码来更改图像。但是picture变量是一个常量,不能更改:
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
}
我想做的是防止仅前置摄像头图像被翻转
如果您使用默认相机,则无法防止相机防止翻转图像。为此,您需要使用AVFoundation创建自己的摄像机,并在此应用您的逻辑。
如果您准备使用任何第三方库,则可以检查LEMirroredImagePicker
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句