如何在swift 5的预览视图中翻转UIImagePickerController中的倒置自拍图像



初始化图像选择器

imagePicker.sourceType = UIImagePickerController.SourceType.camera
//If you dont want to edit the photo then you can set allowsEditing to false
imagePicker.allowsEditing = false
imagePicker.delegate = self
imagePicker.sourceType = .camera
imagePicker.cameraDevice = .front
imagePicker.cameraCaptureMode = .photo
//            imagePicker.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
imagePicker.cameraOverlayView = nil
imagePicker.showsCameraControls = true


self.present(imagePicker, animated: true, completion: nil)

ImagePickerController扩展

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
guard var image = info [.originalImage] as? UIImage else {
return
}

if picker.cameraDevice == UIImagePickerController.CameraDevice.front {
image = UIImage(cgImage: image.cgImage!, scale: image.scale, orientation:.leftMirrored)
} else {
print("back")
}
picker.dismiss(animated: true)
}

从自拍相机拍摄的图像被翻转。我们如何解决这个问题?

//MARK: -  CGAffineTransform(scaleX: CGFloat, y: CGFloat) initializer helps flipping image according to x and y values
image.transform = CGAffineTransform(scaleX: -1, y: 1)
//image is imageView
Helpful references:  You can find the all project codes in GitHub repo link and the other methods of flipping, and descriptions are exist in apple documentation link from below links. 
https://github.com/ahmetbostanciklioglu/ImagePickerController.git
https://developer.apple.com/documentation/coregraphics/1455016-cgaffinetransformmakescale

相关内容

  • 没有找到相关文章

最新更新