当我使用相机在我的应用程序中拍照时,图像会被颠倒显示。
我使用UIImagePickerController拍摄照片,然后选择我喜欢的照片。选择后,执行以下功能:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
print("image selected ...")
// Get picked image info dictionary
let image = info[UIImagePickerControllerOriginalImage] as! UIImage
// Image is upside down. Need to re-orient
// Add captured and selected image to your Photo Library
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
// Create PDFDocument object and display in PDFView
let document = createPDFDataFromImage(image: image)
myPDFView.document = document
// Dimiss imagePicker
dismiss(animated: true, completion: nil)
}
func createPDFDataFromImage(image: UIImage) -> PDFDocument{
let document = PDFDocument.init()
let imagePDF = PDFPage.init(image: image)
document.insert(imagePDF!, at: 0)
return document
}
如何阻止图片颠倒?
答案 0 :(得分:0)
这是一种方法:
var flippedImage: UIImage?
if let origImage = UIImage(named: "s1") {
if let cg = origImage.cgImage {
flippedImage = UIImage(cgImage: cg, scale: 1.0, orientation: UIImageOrientation.downMirrored)
}
}
theImageView.image = flippedImage