【问题标题】:Pictures taken with the camera in my app are upside down [duplicate]在我的应用程序中使用相机拍摄的照片是颠倒的[重复]
【发布时间】:2018-07-30 17:45:57
【问题描述】:

当我使用相机在我的应用中拍照时,图像会倒置显示。

我使用 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
}

如何防止图片倒置?

【问题讨论】:

  • 你真的需要翻转图像吗?您想要一个可以保存的新图像,即翻转版本吗?或者你只是想把它倒过来显示?
  • 我只需要把它倒过来查看——保存之前
  • 所以你想保存一个颠倒的版本吗?
  • 发生的事情是当我拍照并显示时,由于某种原因它倒置了,所以我需要将它翻转 180 度
  • @Fogmeister 请查看更新

标签: ios swift pdf uiimage


【解决方案1】:

这是一种方法:

    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

【讨论】:

    猜你喜欢
    • 2016-07-19
    • 1970-01-01
    • 2012-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    相关资源
    最近更新 更多